Notebooks and cdf as learning support for an engineering course

Milana Lima dos Santos, Universidade de São Paulo, Brasil

Abstract

This talk focus on the experience of intensively using Wolfram Mathematica dynamic functionalities to present same topics in electrical engineering subjects in an undergraduate course. Also, it shows how the instructional material are based on Mathematica notebooks and the engagement of students in such activity. As engineering courses are facing the challenge of including interdisciplinary subjects keeping, or even reducing, the credit hours in classroom, well-developed Mathematica notebooks can provide a graphic and interactive way for students to experiment, in a graphic interface, same topics whose mathematical demonstration is not so simple. It is particulary useful for subjects that are not part of the ‘core’ subjects, such as ‘Basic and Applied Electricity’ for a non-electrical engineering program, such as Chemical or Production Engineering. Notebooks were developed to demonstrate the impact of reactive eletric power in the magnitude and phase of supplied current for a given load, or how the rotating fields are induced in electrical motors. Notebooks with more complex functionalities were developed to clarify advanced topics even for Electrical Engineering students, such as circuits with relays and timers, assymmetric short-circuit calculation, operation curves for wind turbines and generators, and curve-based selection of eletric motors. Some undergraduate students have developed some of these notebooks as their course conclusion project.

The Polytechnic School of the University of São Paulo

• 4800 students enrolled for 17 engineering undergraduate programs (Electrical [with 5 emphasis], Mechanics, Civil, Chemical, Mecathronics, Metallurgical, Materials, Computation, Environment, Mining, Petroleum, Production and Naval)

• Electric Energy and Automation Enginnering Department

• Courses about

• Automation

• Power Electronics

• Fundamentals of Electricity and Power Systems (*)

• Energy (*)

• Electrical Machines

• Power Systems

(*) courses are also part of non-electrical engineering undergraduate programs

Use of Mathematica to build classroom presentations

Animation functionality of beamer package for LaTeX

A large amount of pictures are sequentially created using Mathematica

Electric motor


© Toshinori baba /  https://commons.wikimedia.org/wiki/File:MT61_DC_assembly.JPG / CC-BY-SA-3.0

Induced forces in a coil, function of electric current and magnetic field (DC)

Pane[Manipulate[(
opc=1;
angGapEscovas=1.30;raioescovas=.085;largescovas=0.1;zescovas=2.5;
correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[Reverse@{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[Reverse@{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[Reverse@{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[Reverse@{centroespira+{largespira*0.35-0.1,0,-1.7},centroespira+{-largespira*0.35-0.1,0,-1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[Reverse@{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};
Which[
opc==2,(angGapEscovas=1.30;raioescovas=.085;largescovas=0.1;zescovas=2.5;
correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[Reverse@{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[Reverse@{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[Reverse@{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[Reverse@{centroespira+{largespira*0.35-0.1,0,-1.7},centroespira+{-largespira*0.35-0.1,0,-1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[Reverse@{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};)
,opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],(
correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[{centroespira+{largespira*0.35-0.1,0,-1.4},centroespira+{-largespira*0.35-0.1,0,-1.4}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};
)
,opc==1&&(Mod[angrot,2.Pi]≥2.Pi-angGapEscovas||Mod[angrot,2.Pi]<angGapEscovas),(correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[Reverse@{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[Reverse@{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[Reverse@{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[Reverse@{centroespira+{largespira*0.35-0.1,0,-1.7},centroespira+{-largespira*0.35-0.1,0,-1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[Reverse@{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};)
,opc==1,(correntes={})];
(*angrot=Pi/16.;*)
espira2=Rotate[espira,angrot,{0,0,1},{0.4,0,0}];
correntes2=Rotate[correntes,angrot,{0,0,1},{0.4,0,0}];
angGapEscovas=1.30;raioescovas=.085;largescovas=0.1;zescovas=2.5;
escovas={Thickness[0.005]
,Lighter[Black,0.7],Line@Table[{raioescovas{Cos@x, Sin@x,0}+{largespira,0,zescovas},raioescovas{Cos@x, Sin@x,0}+{largespira,0,zescovas+largescovas}},{x,-angGapEscovas,angGapEscovas,0.003}]
,Line@Table[{raioescovas{Cos@x, Sin@x,0}+{largespira,0,zescovas},raioescovas{Cos@x,Sin@x,0}+{largespira,0,zescovas+largescovas}},{x,Pi-angGapEscovas,angGapEscovas+Pi,0.003}],Lighter[Black,0.0],Text[Style["+",{44,Bold}],raioescovas{-1.8,0,0.2}+{largespira,0,zescovas}],Text[Style["-",{44,Bold}],raioescovas{1.0,-1.,0.2}+{largespira,0,zescovas}]
};
Which[opc==1,(
campo2=campo;
F34={{-largespira*Cos@angrot,-largespira*Sin@angrot,1}+{largespira,0,0},{-largespira*Cos@angrot,-largespira*Sin@angrot,1}+{largespira,0,0}+(Differences@forcas1)[[1]]};
F12={{largespira*Cos@angrot,largespira*Sin@angrot,1}+{largespira,0,0},{largespira*Cos@angrot,largespira*Sin@angrot,1}+{largespira,0,0}+(Differences@forcas2)[[1]]};),
opc==2,
(campo2=Rotate[campo,angrot,{0,0,1},{0.4,0,0}];
)
];
forcasr={Arrowheads[0.035],Thickness[0.008],Blue,Arrow[Which[opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],(*Reverse@F34*){F34[[1]],2*F34[[1]]- F34[[2]]}
,opc==1&&Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],{},True,F34]],If[!Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],Text[Style["(OverVector[(Subscript[F, 34])])",{32,Bold}],If[opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],1.1(2*F34[[1]]- F34[[2]]),1.1*F34[[2]]]],Null],
Arrow[Which[opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],(*Reverse@F12*){F12[[1]],2*F12[[1]]- F12[[2]]}
,opc==1&&Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],{},True,F12]],If[!Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],Text[Style["(OverVector[(Subscript[F, 12])])",{32,Bold}],If[opc==1&&angrot>0.5Pi&&angrot<1.5Pi,1.1(2*F12[[1]]- F12[[2]]),1.1*F12[[2]]]],Null]};
d=Graphics3D[{Transparent,(*eixos,*)Gray,Opacity[1],espira2,campo2,correntes2,Which[opc==1,{escovas,forcasr},opc==2,Rotate[forcas,angrot,{0,0,1},{0.4,0,0}]](*,cota1,cota2*)},ViewPoint->pontovista,ViewVertical->{0,1,0},PlotRange ->{{-0.5,1.5},{-0.5,1},{-0.5,3.85}},Boxed->False,ImageSize->Full,Background->Transparent];
d2=Graphics3D[{Transparent,(*eixos,*)Gray,Opacity[1],espira2,correntes2,campo2,Which[opc==1,{escovas,forcasr},opc==2,Rotate[forcas,angrot,{0,0,1},{0.4,0,0}]],eixorot(*,cota1,cota2*)},ViewPoint->pontovista,ViewVertical->{0,1,0},PlotRange ->{{-0.3,1.0},{-1.5,1.5},{0.,3.25}},Boxed->False,ImageSize->650,Background->Transparent]),{angrot,0.,2 Pi,0.035,AnimationRate->7},TrackedSymbols:>{angrot},Initialization:>(
eixo1={-1,0,0};eixo2={1,0,0};
largespira=0.4;
centroespira={largespira,0,1};
espira={{Tube[{centroespira+{-largespira*0.15,0,1.6},centroespira+{-largespira*0.15,0,1},centroespira+{-largespira,0,1},centroespira+{-largespira,0,-1},centroespira+{largespira,0,-1},centroespira+{largespira,0,1},centroespira+{largespira*0.15,0,1},centroespira+{largespira*0.15,0,1.6}},0.02]}(*,{Black,Text[Style["1",{20,Bold}],centroespira+{largespira,0,1}+{0.1,0.05,0.35}],Text[Style["2",{20,Bold}],centroespira+{largespira,0,-1}+{0.05,0.05,-0.15}],
Text[Style["3",{20,Bold}],centroespira+{-largespira,0,-1}+{-0.05,0.05,-0.15}],
Text[Style["4",{20,Bold}],centroespira+{-largespira,0,1}+{0-0.02,0.05,0.10}]}*)};
ptocampo=centroespira+{0,0,0};
campo={Black,Thickness[0.005],Arrowheads[0.020],Arrow[{ptocampo,ptocampo+{0.3,0,0}}],Text[Style["(OverVector[B])",32,Bold],ptocampo+{0.22,0.02,-0.3}]};
eixos={Thickness[0.005],Arrowheads[0.02],Lighter[Black,0.7], Opacity[1],Arrow[{{2*largespira,0,0},{1.4,0,0}}],Text[Style["x",{16,Bold,Italic}],1.05*{1.2,0.08,0}],
Arrow[{{0,0,0},{0,1,0}}],Text[Style["y",{16,Bold,Italic}],1.05{0,1.05,0}],Arrow[{{0,0,1},{0,0,2.5}}],Text[Style["z",{16,Bold,Italic}],1.05*{0,0,2.5}+{0,0,-0.05}]};

forcas1=Reverse@{centroespira+{-largespira,0,0},centroespira+{-largespira,0.7,0}};
forcas2=Reverse@{centroespira+{largespira,0.7,0},centroespira+{largespira,0,0}};
forcas={Arrowheads[0.035],Thickness[0.008],Blue,Arrow[forcas1],Text[Style["(OverVector[(Subscript[F, 34])])",{32,Bold}],centroespira+{-largespira-0.05,0.8,0}],
Arrow[forcas2],Text[Style["(OverVector[(Subscript[F, 12])])",{32,Bold}],centroespira+{largespira+0.08,0.8,0}]};
eixorot={Thickness[0.005],Dashing[0.01],Gray,Line[{centroespira+{0,0,1.5},centroespira+{0,0,-1}}]};
p1=centroespira+{largespira,-0.08,0.7}+{0.3,0.05,0.30};p2=centroespira+{largespira,-0.08,-1}+{0.3,0.05,0.0};
cota1={Darker[Green,0.3],Thickness@0.003,Line@{p1,p1+0.4*(p2-p1)},Text[Style["C",{20,Bold}],0.5*(p1+p2)],Line@{p1+0.6*(p2-p1),p1+1*(p2-p1)},Line@{p1+{0.1,0,0},p1+{-0.1,0,0}},Line@{p2+{-0.1,0,0},p2+{0.1,0,0}}};
p1=centroespira+{largespira*1.0,-0.04,1.9};p2=centroespira+{-largespira*1.0,-0.04,1.9};
cota2={Darker[Green,0.3],Thickness@0.003,Line@{p1,p1+0.4*(p2-p1)},Text[Style["ℓ",{28,Bold,FontFamily->"Symbol"}],0.5*(p1+p2)],Line@{p1+0.6*(p2-p1),p1+1*(p2-p1)},Line@{p1+{0,0,0.1},p1+{0,0,-0.1}},Line@{p2+{0,0,-0.1},p2+{0,0,0.1}}};
pontovista={0.38,0.22,1.16};
pontovista={0.33,0.26,1.08};
)],1500,Alignment->Center]

Induced forces in a coil, function of electric current and magnetic field (AC)

Pane[Manipulate[(
opc=2;
angGapEscovas=1.30;raioescovas=.085;largescovas=0.1;zescovas=2.5;
correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[Reverse@{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[Reverse@{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[Reverse@{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[Reverse@{centroespira+{largespira*0.35-0.1,0,-1.7},centroespira+{-largespira*0.35-0.1,0,-1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[Reverse@{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};
Which[
opc==2,(angGapEscovas=1.30;raioescovas=.085;largescovas=0.1;zescovas=2.5;
correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[Reverse@{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[Reverse@{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[Reverse@{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[Reverse@{centroespira+{largespira*0.35-0.1,0,-1.7},centroespira+{-largespira*0.35-0.1,0,-1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[Reverse@{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};)
,opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],(
correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[{centroespira+{largespira*0.35-0.1,0,-1.4},centroespira+{-largespira*0.35-0.1,0,-1.4}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};
)
,opc==1&&(Mod[angrot,2.Pi]≥2.Pi-angGapEscovas||Mod[angrot,2.Pi]<angGapEscovas),(correntes={Arrowheads[0.020],Thickness[0.006],Red, Arrow[Reverse@{centroespira+{largespira*0.15,0,2.2},centroespira+{largespira*0.15,0,1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira*0.15+0.05,-0.07,1.6}],*)
Arrow[Reverse@{centroespira+{-largespira*0.15,0,1.7},centroespira+{-largespira*0.15,0,2.2}}],
(*Text[Style["I",{20,Bold}],centroespira+{-largespira*0.15-0.05,0.07,1.6}],*)
Arrow[Reverse@{centroespira+{largespira+0.1,0,0.3+0.5},centroespira+{largespira+0.1,0,-0.3+0.5}}],(*Text[Style["I",{20,Bold}],centroespira+{largespira+0.1,0,0}+{0.05,-0.1,0}],*)
Arrow[Reverse@{centroespira+{largespira*0.35-0.1,0,-1.7},centroespira+{-largespira*0.35-0.1,0,-1.7}}],(*Text[Style["I",{20,Bold}],centroespira+{0,0,-1.3}+{0,0.07,0}],*)
Arrow[Reverse@{centroespira+{-largespira-0.1,0,-0.1+0.2},centroespira+{-largespira-0.1,0,0.5+0.2}}](*,Text[Style["I",{20,Bold}],centroespira+{-largespira-0.3,0,0}+{0.05,0.010,-0.3}]*)};)
,opc==1,(correntes={})];
(*angrot=Pi/16.;*)
espira2=Rotate[espira,angrot,{0,0,1},{0.4,0,0}];
correntes2=Rotate[correntes,angrot,{0,0,1},{0.4,0,0}];
angGapEscovas=1.30;raioescovas=.085;largescovas=0.1;zescovas=2.5;
escovas={Thickness[0.005]
,Lighter[Black,0.7],Line@Table[{raioescovas{Cos@x, Sin@x,0}+{largespira,0,zescovas},raioescovas{Cos@x, Sin@x,0}+{largespira,0,zescovas+largescovas}},{x,-angGapEscovas,angGapEscovas,0.003}]
,Line@Table[{raioescovas{Cos@x, Sin@x,0}+{largespira,0,zescovas},raioescovas{Cos@x,Sin@x,0}+{largespira,0,zescovas+largescovas}},{x,Pi-angGapEscovas,angGapEscovas+Pi,0.003}],Lighter[Black,0.0],Text[Style["+",{44,Bold}],raioescovas{-1.8,0,0.2}+{largespira,0,zescovas}],Text[Style["-",{44,Bold}],raioescovas{1.0,-1.,0.2}+{largespira,0,zescovas}]
};
Which[opc==1,(
campo2=campo;
F34={{-largespira*Cos@angrot,-largespira*Sin@angrot,1}+{largespira,0,0},{-largespira*Cos@angrot,-largespira*Sin@angrot,1}+{largespira,0,0}+(Differences@forcas1)[[1]]};
F12={{largespira*Cos@angrot,largespira*Sin@angrot,1}+{largespira,0,0},{largespira*Cos@angrot,largespira*Sin@angrot,1}+{largespira,0,0}+(Differences@forcas2)[[1]]};),
opc==2,
(campo2=Rotate[campo,angrot,{0,0,1},{0.4,0,0}];
)
];
forcasr={Arrowheads[0.035],Thickness[0.008],Blue,Arrow[Which[opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],(*Reverse@F34*){F34[[1]],2*F34[[1]]- F34[[2]]}
,opc==1&&Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],{},True,F34]],If[!Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],Text[Style["(OverVector[(Subscript[F, 34])])",{32,Bold}],If[opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],1.1(2*F34[[1]]- F34[[2]]),1.1*F34[[2]]]],Null],
Arrow[Which[opc==1&&Between[Mod[angrot,2.Pi],{Pi-angGapEscovas,Pi+angGapEscovas}],(*Reverse@F12*){F12[[1]],2*F12[[1]]- F12[[2]]}
,opc==1&&Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],{},True,F12]],If[!Between[Mod[angrot,2.Pi],{{angGapEscovas,Pi-angGapEscovas},{Pi+angGapEscovas,2.Pi-angGapEscovas}}],Text[Style["(OverVector[(Subscript[F, 12])])",{32,Bold}],If[opc==1&&angrot>0.5Pi&&angrot<1.5Pi,1.1(2*F12[[1]]- F12[[2]]),1.1*F12[[2]]]],Null]};
d=Graphics3D[{Transparent,(*eixos,*)Gray,Opacity[1],espira2,campo2,correntes2,Which[opc==1,{escovas,forcasr},opc==2,Rotate[forcas,angrot,{0,0,1},{0.4,0,0}]](*,cota1,cota2*)},ViewPoint->pontovista,ViewVertical->{0,1,0},PlotRange ->{{-0.5,1.5},{-0.5,1},{-0.5,3.85}},Boxed->False,ImageSize->Full,Background->Transparent];
d2=Graphics3D[{Transparent,(*eixos,*)Gray,Opacity[1],espira2,correntes2,campo2,Which[opc==1,{escovas,forcasr},opc==2,Rotate[forcas,angrot,{0,0,1},{0.4,0,0}]],eixorot(*,cota1,cota2*)},ViewPoint->pontovista,ViewVertical->{0,1,0},PlotRange ->{{-0.3,1.0},{-1.5,1.5},{0.,3.25}},Boxed->False,ImageSize->650,Background->Transparent]),{angrot,0.,2 Pi,0.035,AnimationRate->7},TrackedSymbols:>{angrot},Initialization:>(
eixo1={-1,0,0};eixo2={1,0,0};
largespira=0.4;
centroespira={largespira,0,1};
espira={{Tube[{centroespira+{-largespira*0.15,0,1.6},centroespira+{-largespira*0.15,0,1},centroespira+{-largespira,0,1},centroespira+{-largespira,0,-1},centroespira+{largespira,0,-1},centroespira+{largespira,0,1},centroespira+{largespira*0.15,0,1},centroespira+{largespira*0.15,0,1.6}},0.02]}(*,{Black,Text[Style["1",{20,Bold}],centroespira+{largespira,0,1}+{0.1,0.05,0.35}],Text[Style["2",{20,Bold}],centroespira+{largespira,0,-1}+{0.05,0.05,-0.15}],
Text[Style["3",{20,Bold}],centroespira+{-largespira,0,-1}+{-0.05,0.05,-0.15}],
Text[Style["4",{20,Bold}],centroespira+{-largespira,0,1}+{0-0.02,0.05,0.10}]}*)};
ptocampo=centroespira+{0,0,0};
campo={Black,Thickness[0.005],Arrowheads[0.020],Arrow[{ptocampo,ptocampo+{0.3,0,0}}],Text[Style["(OverVector[B])",32,Bold],ptocampo+{0.22,0.02,-0.3}]};
eixos={Thickness[0.005],Arrowheads[0.02],Lighter[Black,0.7], Opacity[1],Arrow[{{2*largespira,0,0},{1.4,0,0}}],Text[Style["x",{16,Bold,Italic}],1.05*{1.2,0.08,0}],
Arrow[{{0,0,0},{0,1,0}}],Text[Style["y",{16,Bold,Italic}],1.05{0,1.05,0}],Arrow[{{0,0,1},{0,0,2.5}}],Text[Style["z",{16,Bold,Italic}],1.05*{0,0,2.5}+{0,0,-0.05}]};

forcas1=Reverse@{centroespira+{-largespira,0,0},centroespira+{-largespira,0.7,0}};
forcas2=Reverse@{centroespira+{largespira,0.7,0},centroespira+{largespira,0,0}};
forcas={Arrowheads[0.035],Thickness[0.008],Blue,Arrow[forcas1],Text[Style["(OverVector[(Subscript[F, 34])])",{32,Bold}],centroespira+{-largespira-0.05,0.8,0}],
Arrow[forcas2],Text[Style["(OverVector[(Subscript[F, 12])])",{32,Bold}],centroespira+{largespira+0.08,0.8,0}]};
eixorot={Thickness[0.005],Dashing[0.01],Gray,Line[{centroespira+{0,0,1.5},centroespira+{0,0,-1}}]};
p1=centroespira+{largespira,-0.08,0.7}+{0.3,0.05,0.30};p2=centroespira+{largespira,-0.08,-1}+{0.3,0.05,0.0};
cota1={Darker[Green,0.3],Thickness@0.003,Line@{p1,p1+0.4*(p2-p1)},Text[Style["C",{20,Bold}],0.5*(p1+p2)],Line@{p1+0.6*(p2-p1),p1+1*(p2-p1)},Line@{p1+{0.1,0,0},p1+{-0.1,0,0}},Line@{p2+{-0.1,0,0},p2+{0.1,0,0}}};
p1=centroespira+{largespira*1.0,-0.04,1.9};p2=centroespira+{-largespira*1.0,-0.04,1.9};
cota2={Darker[Green,0.3],Thickness@0.003,Line@{p1,p1+0.4*(p2-p1)},Text[Style["ℓ",{28,Bold,FontFamily->"Symbol"}],0.5*(p1+p2)],Line@{p1+0.6*(p2-p1),p1+1*(p2-p1)},Line@{p1+{0,0,0.1},p1+{0,0,-0.1}},Line@{p2+{0,0,-0.1},p2+{0,0,0.1}}};
pontovista={0.38,0.22,1.16};
pontovista={0.33,0.26,1.08};
)],1500,Alignment->Center]

Rotating magnetic fields in an alternate current motor

saida3=Pane[Manipulate[(
vnparpolos={1};
vcentrofigura={{0,0},{300,0},{600,0},{900,0},{1200,0}};
vraioestator={100,100,100,100,100};
vraiobobinas=0.5*{10,10,10,10,10};
elem=1;
saidai={};
saidasobobinas={};
auxarq=If[figima==True,"_com_ima_","_sem_ima_"]<>If[sobobinas==True,"so_bobinas_",""]<>If[tempo==True,"tempo_",""]<>If[mostralinhas==True,"linhas",""];(*string para identificar o arquivo*)
While[elem≤Length[vnparpolos],(
nparpolos=vnparpolos[[elem]];
centroestator=vcentrofigura[[elem]];
raioestator=vraioestator[[elem]];
raiobobinas=vraiobobinas[[elem]];
vcentroestator=Table[centroestator,{x,1,2*nparpolos}];
escalagrafH=1500000;
minmaxH={0.5,Infinity};
(*1 par de polos*)
Which[nparpolos==1,(
ra1s=vcentroestator+Table[(raioestator+k*raiobobinas)*vu[0*Pi/3+Pi/2.],{k,{1,3}}];
ra1e=vcentroestator+Table[(raioestator+k*raiobobinas)*vu[3*Pi/3+Pi/2.],{k,{1,3}}];
rb1s=vcentroestator+Table[(raioestator+k*raiobobinas)*vu[2*Pi/3+Pi/2.],{k,{1,3}}];
rb1e=vcentroestator+Table[(raioestator+k*raiobobinas)*vu[5*Pi/3+Pi/2.],{k,{1,3}}];
rc1s=vcentroestator+Table[(raioestator+k*raiobobinas)*vu[4*Pi/3+Pi/2.],{k,{1,3}}];
rc1e=vcentroestator+Table[(raioestator+k*raiobobinas)*vu[1*Pi/3+Pi/2.],{k,{1,3}}];
raiosmedida={0};
vetoresmedida={{vu[-Pi/2+Pi/2.]}};
escalagrafH=0.7*150000000;
ima=If[figima==True,ima2p,noima];)
,nparpolos==2,(
(*2 pares de polos*)
(*vu = vetor unitário, função customizada*)
ra1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[9*Pi/12+Pi/2.],(raioestator+k*raiobobinas)*vu[21*Pi/12+Pi/2.]},{k,{1,3}}],1];
ra1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[3*Pi/12+Pi/2.],(raioestator+k*raiobobinas)*vu[15*Pi/12+Pi/2.]},{k,{1,3}}],1];
rb1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[1*Pi/12+Pi/2.],(raioestator+k*raiobobinas)*vu[13*Pi/12+Pi/2.]},{k,{1,3}}],1];
rb1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[7*Pi/12+Pi/2.],(raioestator+k*raiobobinas)*vu[19*Pi/12+Pi/2.]},{k,{1,3}}],1];
rc1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[5*Pi/12+Pi/2.],(raioestator+k*raiobobinas)*vu[17*Pi/12+Pi/2.]},{k,{1,3}}],1];
rc1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[11*Pi/12+Pi/2.],(raioestator+k*raiobobinas)*vu[23*Pi/12+Pi/2.]},{k,{1,3}}],1];
raiosmedida={40};
vetoresmedida={{vu[-Pi/2+Pi/2.],vu[0+Pi/2.],vu[Pi/2+Pi/2.],vu[Pi+Pi/2.]}};
escalagrafH=0.72*40000000;
minmaxH={12.5,12.6};
minmaxH={0.5,Infinity};
ima=If[figima==True,ima4p,noima];)
,nparpolos==3,(
ra1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[3*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[9*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[15*Pi/9+Pi/2.]},{k,{1,3}}],1];
ra1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[0*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[6*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[12*Pi/9+Pi/2.]},{k,{1,3}}],1];
rb1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[5*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[11*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[17*Pi/9+Pi/2.]},{k,{1,3}}],1];
rb1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[2*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[8*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[14*Pi/9+Pi/2.]},{k,{1,3}}],1];
rc1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[7*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[13*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[1*Pi/9+Pi/2.]},{k,{1,3}}],1];
rc1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[4*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[10*Pi/9+Pi/2.],(raioestator+k*raiobobinas)*vu[16*Pi/9+Pi/2.]},{k,{1,3}}],1];
raiosmedida={45};
vetoresmedida={{vu[-3*Pi/6+Pi/2.],vu[-1*Pi/6+Pi/2.],vu[Pi/6+Pi/2.],vu[3*Pi/6+Pi/2.],vu[5*Pi/6+Pi/2.],vu[7*Pi/6+Pi/2.]}};
escalagrafH=0.5*50000000;
minmaxH={10,14};
minmaxH={0.5,Infinity};
ima=If[figima==True,ima6p,noima];)
,nparpolos==4,(
ra1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[3*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[15*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[27*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[39*Pi/24+Pi/2.]},{k,{1,3}}],1];
ra1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[9*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[21*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[33*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[45*Pi/24+Pi/2.]},{k,{1,3}}],1];
rb1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[7*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[19*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[31*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[43*Pi/24+Pi/2.]},{k,{1,3}}],1];
rb1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[13*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[25*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[37*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[1*Pi/24+Pi/2.]},{k,{1,3}}],1];
rc1s=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[11*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[23*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[35*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[47*Pi/24+Pi/2.]},{k,{1,3}}],1];
rc1e=vcentroestator+Flatten[Table[{(raioestator+k*raiobobinas)*vu[17*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[29*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[41*Pi/24+Pi/2.],(raioestator+k*raiobobinas)*vu[5*Pi/24+Pi/2.]},{k,{1,3}}],1];
raiosmedida={45};
vetoresmedida={{vu[-2*Pi/4+Pi/2.],vu[-1*Pi/4+Pi/2.],vu[0*Pi/4+Pi/2.],vu[1*Pi/4+Pi/2.],vu[2*Pi/4+Pi/2.],vu[3*Pi/4+Pi/2.],vu[4*Pi/4+Pi/2.],vu[5*Pi/4+Pi/2.]}};
escalagrafH=0.35*100000000;
minmaxH={11,11.4};
minmaxH={0.5,Infinity};
ima=If[figima==True,ima8p,noima];
)];
pontosmedida={};
Module[{c1,c2},(For[c1=1,c1≤Length[raiosmedida],c1++,(
For[c2=1,c2≤Length[vetoresmedida[[c1]]],c2++,(
pontosmedida=Append[pontosmedida,centroestator+raiosmedida[[c1]]*vetoresmedida[[c1,c2]]]
)];
)])];
(*xmin=-100;xmax=100;stepx=25;nelemx=(xmax-xmin)/stepx+1;
ymin=-100;ymax=100;stepy=25;nelemy=(ymax-xmin)/stepy+1;
npontosmedida=nelemx*nelemy;
pontosmedida={};pontosmedida=Table[0,{i,npontosmedida},{j,2}];
For[c1=1,c1<=npontosmedida,c1++,(
pontosmedida[[c1,1]]=Quotient[c1-1,nelemy]*stepx+xmin;
pontosmedida[[c1,2]]=Mod[c1-1,nelemy]*stepy+ymin;
)];*)
npontosmedida=Length[pontosmedida];
pontosmedida2=Table[{0,0},{x,1,npontosmedida}];
HpontosmedidaA=Table[0,{x,1,npontosmedida}];
HpontosmedidaB=Table[0,{x,1,npontosmedida}];HpontosmedidaC=Table[0,{x,1,npontosmedida}];
maxH=0;
Module[{c},(For[c=1,c≤npontosmedida,c++,(
pontosmedida2[[c]]=(pontosmedida[[c]]-centroestator).{{Cos[-omega*t/nparpolos],-Sin[-omega*t/nparpolos]},{Sin[-omega*t/nparpolos],Cos[-omega*t/nparpolos]}}+centroestator;
)])];
Module[{c},(For[c=1,c≤npontosmedida,c++,
(*Hpontosmedida[[c3]]=H2[pontosmedida[[c3]],Table[ia[t],{x,1,nparpolos}],ra1s]
+H2[pontosmedida[[c3]],Table[-ia[t],{x,1,nparpolos}],ra1e]
+H2[pontosmedida[[c3]],Table[ib[t],{x,1,nparpolos}],rb1s]
+H2[pontosmedida[[c3]],Table[-ib[t],{x,1,nparpolos}],rb1e]
+H2[pontosmedida[[c3]],Table[ic[t],{x,1,nparpolos}],rc1s]
+H2[pontosmedida[[c3]],Table[-ic[t],{x,1,nparpolos}],rc1e]*)
(HpontosmedidaA[[c]]=H2[pontosmedida2[[c]],Table[ia[t],{x,1,2*nparpolos}],ra1s]
+H2[pontosmedida2[[c]],Table[-ia[t],{x,1,2*nparpolos}],ra1e];
HpontosmedidaB[[c]]=H2[pontosmedida2[[c]],Table[ib[t],{x,1,2*nparpolos}],rb1s]
+H2[pontosmedida2[[c]],Table[-ib[t],{x,1,2*nparpolos}],rb1e];
HpontosmedidaC[[c]]=H2[pontosmedida2[[c]],Table[ic[t],{x,1,2*nparpolos}],rc1s]
+H2[pontosmedida2[[c]],Table[-ic[t],{x,1,2*nparpolos}],rc1e];)];)];
HpontosmedidaABC=HpontosmedidaA+HpontosmedidaB+HpontosmedidaC;
maxH=Max[maxH,Max[Abs[HpontosmedidaABC]]];
ka=Chop[ia[t]]/imax;
kb=Chop[ib[t]]/imax;
kc=Chop[ic[t]]/imax;
(*ka=1;
kb=1;kc=1;*)
desslots={AbsoluteThickness[1],Lighter[Red,1-Abs[ka]],slot2[ra1s,Table[1*Sign[ka],{x,1,2*nparpolos}],raiobobinas],slot2[ra1e,Table[-1*Sign[ka],{x,1,2*nparpolos}],raiobobinas],
Lighter[Blue,1-Abs[kb]],slot2[rb1s,Table[1*Sign[kb],{x,1,2*nparpolos}],raiobobinas],slot2[rb1e,Table[-1*Sign[kb],{x,1,2*nparpolos}],raiobobinas],
Lighter[Green,1-Abs[kc]],slot2[rc1s,Table[1*Sign[kc],{x,1,2*nparpolos}],raiobobinas],slot2[rc1e,Table[-1*Sign[kc],{x,1,2*nparpolos}],raiobobinas]};
desslotsestatico={AbsoluteThickness[1],Red,slot2[ra1s,Table[1,{x,1,2*nparpolos}],raiobobinas],slot2[ra1e,Table[-1,{x,1,2*nparpolos}],raiobobinas],
Lighter[Blue,0.4],slot2[rb1s,Table[1,{x,1,2*nparpolos}],raiobobinas],slot2[rb1e,Table[-1,{x,1,2*nparpolos}],raiobobinas],
Green,slot2[rc1s,Table[1,{x,1,2*nparpolos}],raiobobinas],slot2[rc1e,Table[-1,{x,1,2*nparpolos}],raiobobinas]};
descampoA=gH2[pontosmedida2,escalagrafH*HpontosmedidaA];
descampoB=gH2[pontosmedida2,escalagrafH*HpontosmedidaB];
descampoC=gH2[pontosmedida2,escalagrafH*HpontosmedidaC];
descampoABC1=gH2[pontosmedida2,escalagrafH*HpontosmedidaABC];
maxH=Max[Abs[HpontosmedidaABC]]*escalagrafH;
dimfigima=ImageDimensions[ima];
escalaima1=0.65*2*(Max[raiosmedida]+maxH);(*a maior dimensão da figura do ímã não deve ser maior que 0.90 do diâmetro do tracejado*)
escalaima2=escalaima1*Min[dimfigima]/Max[dimfigima];
(*a menor dimensão é tal que a proporção da figura é mantida*)
escalaima=If[Max[dimfigima]==dimfigima[[1]],{escalaima1,escalaima2},{escalaima2,escalaima1}];
(*raiotraco=Sqrt[(pontosmedida2[[1,1]]-centroestator[[1]])^2+(pontosmedida2[[1,2]]-centroestator[[2]])^2];
*)
(*angulo do primeiro ponto de medida*)
anginicial=ArcTan[vetoresmedida[[1,1,2]]*If[vetoresmedida[[1,1,1]]≠0,1/vetoresmedida[[1,1,1]],Infinity]];
raiotraco=(Max[raiosmedida]+maxH);
angranhura=2.5*raiobobinas/raioestator;
estatorrotor={EdgeForm[Black],FaceForm[Orange],Circle[centroestator,(raioestator)*1.25],FaceForm[White],rodadentada[centroestator,2*3*nparpolos,(raioestator),(raioestator+4*raiobobinas),angranhura,(Pi/(2*3*nparpolos)-0.5*angranhura)],Circle[centroestator,raioestator*0.95]};
(*estatorrotorgr=Rasterize[Graphics[estatorrotor],ImageResolution->300];
estatorrotorgr=ColorReplace[estatorrotorgr,Magenta];*)
(*seta=Graphics@{Line[0.15*{{-1,1/2},{0,0},{-1,-1/2}}]};*)
pts={{-15,102},{-13.5,120},{0,126},{13.5,120},{15,102},{13.5,95},{10.5,91},{6.5,89},{0,87},{-6.5,89},{-10.5,91},{-13.5,95}};
linhas2={(*BSplineCurve[pts,SplineClosed->True],Point[pts]*)};
pts2={
{0,3.2},
{2.7,2.},
{3,-1.6},
{2.75,-3.2},
{2.4,-4},
{1.3,-4.8},
{0,-5},
{-1.3,-4.8},
{-2.4,-4},
{-2.75,-3.2},
{-3.,-1.6},
{-2.7,2.}
};
(*pts2=pts2*raiobobinas+Table[0.5*Total@ra1s,{t,1,Length@pts2}];*)
linhasspline={BSplineCurve[pts2,SplineClosed->True]};
Which[(nparpolos==1&&mostralinhas),
(linhascampo={AbsoluteThickness[1],Arrowheads[{{Automatic,Automatic,Graphics@Line[0.35*{{-1,1/2},{0,0},{-1,-1/2}}]}}],
If[ka≠0,{Lighter[Red,1-Abs[ka]],AbsoluteThickness[3],
GeometricTransformation[BSplineCurve[pts2*raiobobinas+Table[0.5*Total@ra1s,{t,1,Length@pts2}],SplineClosed->True](*{Circle[0.5*Total@ra1s,0.17*{1,0.8}*Norm[0.5*Total@ra1s-pontosmedida[[1]]] ]}*),RotationTransform[(ToPolarCoordinates@(ra1s[[1]]-ra1s[[2]]))[[2]]+Pi/2,0.5*Total@ra1s]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@ra1e,{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@ra1e,0.25*{1,0.8}*Norm[0.5*Total@ra1e-pontosmedida[[1]]] ]*)},RotationTransform[(ToPolarCoordinates@(ra1e[[1]]-ra1e[[2]]))[[2]]+Pi/2,0.5*Total@ra1e]],
GeometricTransformation[Arrow[{0.5*Total@ra1s+0.21*(centroestator-0.5*Total@ra1s),0.5*Total@ra1s+0.23*(centroestator-0.5*Total@ra1s)}],RotationTransform[Sign@ka*Pi/2,0.5*Total@ra1s+0.225*(centroestator-0.5*Total@ra1s)]],GeometricTransformation[Arrow[{0.5*Total@ra1e+0.21*(centroestator-0.5*Total@ra1e),0.5*Total@ra1e+0.23*(centroestator-0.5*Total@ra1e)}],RotationTransform[-Sign@ka*Pi/2,0.5*Total@ra1e+0.225*(centroestator-0.5*Total@ra1e)]]},{}],
If[kb≠0,{Lighter[Blue,1-Abs[kb]],AbsoluteThickness[3],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rb1s,{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rb1s,0.25*{1,0.8}*Norm[0.5*Total@rb1s-pontosmedida[[1]]] ]*)},RotationTransform[(ToPolarCoordinates@(rb1s[[1]]-rb1s[[2]]))[[2]]+Pi/2,0.5*Total@rb1s]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rb1e,{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rb1e,0.25*{1,0.8}*Norm[0.5*Total@rb1e-pontosmedida[[1]]] ]*)},RotationTransform[(ToPolarCoordinates@(rb1e[[1]]-rb1e[[2]]))[[2]]+Pi/2,0.5*Total@rb1e]],GeometricTransformation[Arrow[{0.5*Total@rb1s+0.21*(centroestator-0.5*Total@rb1s),0.5*Total@rb1s+0.23*(centroestator-0.5*Total@rb1s)}],RotationTransform[Sign@kb*Pi/2,0.5*Total@rb1s+0.225*(centroestator-0.5*Total@rb1s)]],GeometricTransformation[Arrow[{0.5*Total@rb1e+0.21*(centroestator-0.5*Total@rb1e),0.5*Total@rb1e+0.23*(centroestator-0.5*Total@rb1e)}],RotationTransform[-Sign@kb*Pi/2,0.5*Total@rb1e+0.225*(centroestator-0.5*Total@rb1e)]]},{}],
If[kc≠0,{Lighter[Green,1-Abs[kc]],AbsoluteThickness[3],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rc1s,{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rc1s,0.25*{1,0.8}*Norm[0.5*Total@rc1s-pontosmedida[[1]]] ]*)},RotationTransform[(ToPolarCoordinates@(rc1s[[1]]-rc1s[[2]]))[[2]]+Pi/2,0.5*Total@rc1s]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rc1e,{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rc1e,0.25*{1,0.8}*Norm[0.5*Total@rc1e-pontosmedida[[1]]] ]*)},RotationTransform[(ToPolarCoordinates@(rc1e[[1]]-rc1e[[2]]))[[2]]+Pi/2,0.5*Total@rc1e]],GeometricTransformation[Arrow[{0.5*Total@rc1s+0.21*(centroestator-0.5*Total@rc1s),0.5*Total@rc1s+0.23*(centroestator-0.5*Total@rc1s)}],RotationTransform[Sign@kc*Pi/2,0.5*Total@rc1s+0.225*(centroestator-0.5*Total@rc1s)]],GeometricTransformation[Arrow[{0.5*Total@rc1e+0.21*(centroestator-0.5*Total@rc1e),0.5*Total@rc1e+0.23*(centroestator-0.5*Total@rc1e)}],RotationTransform[-Sign@kc*Pi/2,0.5*Total@rc1e+0.225*(centroestator-0.5*Total@rc1e)]]},{}]}),
(nparpolos==2&&mostralinhas),
(linhascampo={AbsoluteThickness[1],Arrowheads[{{Automatic,Automatic,Graphics@Line[0.35*{{-1,1/2},{0,0},{-1,-1/2}}]}}],
If[ka≠0,{Lighter[Red,1-Abs[ka]],AbsoluteThickness[3],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@ra1s[[{1,3}]],{t,1,Length@pts2}],SplineClosed->True](*,Point[pts2*raiobobinas+Table[0.5*Total@ra1s[[{1,3}]],{t,1,Length@pts2}]]*)(*Circle[0.5*Total@ra1s[[{1,3}]],0.2*{1,0.8}*Norm[0.5*Total@ra1s[[{1,3}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(ra1s[[1]]-ra1s[[3]]))[[2]]+Pi/2,0.5*Total@ra1s[[{1,3}]] ]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@ra1e[[{1,3}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@ra1e[[{1,3}]],0.2*{1,0.8}*Norm[0.5*Total@ra1e[[{1,3}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(ra1e[[1]]-ra1e[[3]]))[[2]]+Pi/2,0.5*Total@ra1e[[{1,3}]] ]],
GeometricTransformation[Arrow[{0.5*Total@ra1s[[{1,3}]]+0.21*(centroestator-0.5*Total@ra1s[[{1,3}]]),0.5*Total@ra1s[[{1,3}]]+0.23*(centroestator-0.5*Total@ra1s[[{1,3}]])}],RotationTransform[Sign@ka*Pi/2,0.5*Total@ra1s[[{1,3}]]+0.225*(centroestator-0.5*Total@ra1s[[{1,3}]])]],GeometricTransformation[Arrow[{0.5*Total@ra1e[[{1,3}]]+0.21*(centroestator-0.5*Total@ra1e[[{1,3}]]),0.5*Total@ra1e[[{1,3}]]+0.23*(centroestator-0.5*Total@ra1e[[{1,3}]])}],RotationTransform[-Sign@ka*Pi/2,0.5*Total@ra1e[[{1,3}]]+0.225*(centroestator-0.5*Total@ra1e[[{1,3}]])]],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@ra1s[[{2,4}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@ra1s[[{2,4}]],0.2*{1,0.8}*Norm[0.5*Total@ra1s[[{2,4}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(ra1s[[2]]-ra1s[[4]]))[[2]]+Pi/2,0.5*Total@ra1s[[{2,4}]] ]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@ra1e[[{2,4}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@ra1e[[{2,4}]],0.2*{1,0.8}*Norm[0.5*Total@ra1e[[{2,4}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(ra1e[[2]]-ra1e[[4]]))[[2]]+Pi/2,0.5*Total@ra1e[[{2,4}]] ]],
GeometricTransformation[Arrow[{0.5*Total@ra1s[[{2,4}]]+0.21*(centroestator-0.5*Total@ra1s[[{2,4}]]),0.5*Total@ra1s[[{2,4}]]+0.23*(centroestator-0.5*Total@ra1s[[{2,4}]])}],RotationTransform[Sign@ka*Pi/2,0.5*Total@ra1s[[{2,4}]]+0.225*(centroestator-0.5*Total@ra1s[[{2,4}]])]],GeometricTransformation[Arrow[{0.5*Total@ra1e[[{2,4}]]+0.21*(centroestator-0.5*Total@ra1e[[{2,4}]]),0.5*Total@ra1e[[{2,4}]]+0.23*(centroestator-0.5*Total@ra1e[[{2,4}]])}],RotationTransform[-Sign@ka*Pi/2,0.5*Total@ra1e[[{2,4}]]+0.225*(centroestator-0.5*Total@ra1e[[{2,4}]])]]},{}],

If[kb≠0,{Lighter[Blue,1-Abs[kb]],AbsoluteThickness[3],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rb1s[[{1,3}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rb1s[[{1,3}]],0.2*{1,0.8}*Norm[0.5*Total@rb1s[[{1,3}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rb1s[[1]]-rb1s[[3]]))[[2]]+Pi/2,0.5*Total@rb1s[[{1,3}]] ]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rb1e[[{1,3}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rb1e[[{1,3}]],0.2*{1,0.8}*Norm[0.5*Total@rb1e[[{1,3}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rb1e[[1]]-rb1e[[3]]))[[2]]+Pi/2,0.5*Total@rb1e[[{1,3}]] ]],
GeometricTransformation[Arrow[{0.5*Total@rb1s[[{1,3}]]+0.21*(centroestator-0.5*Total@rb1s[[{1,3}]]),0.5*Total@rb1s[[{1,3}]]+0.23*(centroestator-0.5*Total@rb1s[[{1,3}]])}],RotationTransform[Sign@kb*Pi/2,0.5*Total@rb1s[[{1,3}]]+0.225*(centroestator-0.5*Total@rb1s[[{1,3}]])]],GeometricTransformation[Arrow[{0.5*Total@rb1e[[{1,3}]]+0.21*(centroestator-0.5*Total@rb1e[[{1,3}]]),0.5*Total@rb1e[[{1,3}]]+0.23*(centroestator-0.5*Total@rb1e[[{1,3}]])}],RotationTransform[-Sign@kb*Pi/2,0.5*Total@rb1e[[{1,3}]]+0.225*(centroestator-0.5*Total@rb1e[[{1,3}]])]],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rb1s[[{2,4}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rb1s[[{2,4}]],0.2*{1,0.8}*Norm[0.5*Total@rb1s[[{2,4}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rb1s[[2]]-rb1s[[4]]))[[2]]+Pi/2,0.5*Total@rb1s[[{2,4}]] ]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rb1e[[{2,4}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rb1e[[{2,4}]],0.2*{1,0.8}*Norm[0.5*Total@rb1e[[{2,4}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rb1e[[2]]-rb1e[[4]]))[[2]]+Pi/2,0.5*Total@rb1e[[{2,4}]] ]],
GeometricTransformation[Arrow[{0.5*Total@rb1s[[{2,4}]]+0.21*(centroestator-0.5*Total@rb1s[[{2,4}]]),0.5*Total@rb1s[[{2,4}]]+0.23*(centroestator-0.5*Total@rb1s[[{2,4}]])}],RotationTransform[Sign@kb*Pi/2,0.5*Total@rb1s[[{2,4}]]+0.225*(centroestator-0.5*Total@rb1s[[{2,4}]])]],GeometricTransformation[Arrow[{0.5*Total@rb1e[[{2,4}]]+0.21*(centroestator-0.5*Total@rb1e[[{2,4}]]),0.5*Total@rb1e[[{2,4}]]+0.23*(centroestator-0.5*Total@rb1e[[{2,4}]])}],RotationTransform[-Sign@kb*Pi/2,0.5*Total@rb1e[[{2,4}]]+0.225*(centroestator-0.5*Total@rb1e[[{2,4}]])]]},{}],

If[kc≠0,{Lighter[Green,1-Abs[kc]],AbsoluteThickness[3],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rc1s[[{1,3}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rc1s[[{1,3}]],0.2*{1,0.8}*Norm[0.5*Total@rc1s[[{1,3}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rc1s[[1]]-rc1s[[3]]))[[2]]+Pi/2,0.5*Total@rc1s[[{1,3}]] ]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rc1e[[{1,3}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rc1e[[{1,3}]],0.2*{1,0.8}*Norm[0.5*Total@rc1e[[{1,3}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rc1e[[1]]-rc1e[[3]]))[[2]]+Pi/2,0.5*Total@rc1e[[{1,3}]] ]],
GeometricTransformation[Arrow[{0.5*Total@rc1s[[{1,3}]]+0.21*(centroestator-0.5*Total@rc1s[[{1,3}]]),0.5*Total@rc1s[[{1,3}]]+0.23*(centroestator-0.5*Total@rc1s[[{1,3}]])}],RotationTransform[Sign@kc*Pi/2,0.5*Total@rc1s[[{1,3}]]+0.225*(centroestator-0.5*Total@rc1s[[{1,3}]])]],GeometricTransformation[Arrow[{0.5*Total@rc1e[[{1,3}]]+0.21*(centroestator-0.5*Total@rc1e[[{1,3}]]),0.5*Total@rc1e[[{1,3}]]+0.23*(centroestator-0.5*Total@rc1e[[{1,3}]])}],RotationTransform[-Sign@kc*Pi/2,0.5*Total@rc1e[[{1,3}]]+0.225*(centroestator-0.5*Total@rc1e[[{1,3}]])]],
GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rc1s[[{2,4}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rc1s[[{2,4}]],0.2*{1,0.8}*Norm[0.5*Total@rc1s[[{2,4}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rc1s[[2]]-rc1s[[4]]))[[2]]+Pi/2,0.5*Total@rc1s[[{2,4}]] ]],GeometricTransformation[{BSplineCurve[pts2*raiobobinas+Table[0.5*Total@rc1e[[{2,4}]],{t,1,Length@pts2}],SplineClosed->True](*Circle[0.5*Total@rc1e[[{2,4}]],0.2*{1,0.8}*Norm[0.5*Total@rc1e[[{2,4}]]-centroestator] ]*)},RotationTransform[(ToPolarCoordinates@(rc1e[[2]]-rc1e[[4]]))[[2]]+Pi/2,0.5*Total@rc1e[[{2,4}]] ]],
GeometricTransformation[Arrow[{0.5*Total@rc1s[[{2,4}]]+0.21*(centroestator-0.5*Total@rc1s[[{2,4}]]),0.5*Total@rc1s[[{2,4}]]+0.23*(centroestator-0.5*Total@rc1s[[{2,4}]])}],RotationTransform[Sign@kc*Pi/2,0.5*Total@rc1s[[{2,4}]]+0.225*(centroestator-0.5*Total@rc1s[[{2,4}]])]],GeometricTransformation[Arrow[{0.5*Total@rc1e[[{2,4}]]+0.21*(centroestator-0.5*Total@rc1e[[{2,4}]]),0.5*Total@rc1e[[{2,4}]]+0.23*(centroestator-0.5*Total@rc1e[[{2,4}]])}],RotationTransform[-Sign@kc*Pi/2,0.5*Total@rc1e[[{2,4}]]+0.225*(centroestator-0.5*Total@rc1e[[{2,4}]])]]},{}]
}),
True,linhascampo={}];
saidai=Append[saidai,{{estatorrotor,linhascampo,Purple,Opacity[0.8](*,Disk[pontosmedida2[[1]],3]*),Dashed,Purple,AbsoluteThickness[1],Line[{centroestator,centroestator+(Max[raiosmedida]+maxH)*vetoresmedida[[1,1]]}]},{Gray,Dashed,Circle[centroestator,raiotraco,{anginicial,omega*t/nparpolos(*-Pi/2*)}](*,Line[{centroestator,centroestator+raiotraco*vu[omega*t/nparpolos]}]*)},desslots,Purple,If[(nparpolos==1)&&tempo==False,Arrowheads[Medium],If[(nparpolos!=1)&&tempo==False,Arrowheads[0.01],Arrowheads[0.02]]],If[nparpolos==1,AbsoluteThickness[4],AbsoluteThickness[2]],Red,descampoA,Blue,descampoB,Green,descampoC,If[nparpolos==1,AbsoluteThickness[4],AbsoluteThickness[1.5]],Black,If[(nparpolos==1)&&tempo==False,Arrowheads[Medium],If[(nparpolos!=1)&&tempo==False,Arrowheads[Small],Arrowheads[0.015]]],Opacity[0.5],descampoABC1,(*,{Black,Text[ToString[N[ia[t]]],ra1s[[1]]+{0,20}],Text[ToString[N[ib[t]]],rb1s[[1]]+{0,20}],Text[ToString[N[ic[t]]],rc1s[[1]]+{0,20}]}*),Opacity[0.1],Inset[ima,centroestator,ImageDimensions[ima]/2,escalaima,{Cos[omega*t/nparpolos+Pi/2.],Sin[omega*t/nparpolos+Pi/2.]}](*,Inset[estatorrotorgr,centroestator,0.5*ImageDimensions[estatorrotorgr],2*1.25*(raioestator+raiobobinas)(*,ImageDimensions[ima]/2,escalaima,{Cos[omega*t/nparpolos+Pi/2.],Sin[omega*t/nparpolos+Pi/2.]}*)]*),PlotRange->{{-110,110},{-110,110}},PlotRangeClipping->True}];
(*estatorrotor={Circle[centroestator,raioestator+raiobobinas],Circle[centroestator,raioestator-raiobobinas],Disk[centroestator,0.6*raiobobinas]};*)
(*dente=0.8;
auxestatorrotor=Sort@Flatten[Join[Table[{anginicial+2*Pi/(6*nparpolos)+2Pi*y/(4*(6*nparpolos))},{y,1,4*(6*nparpolos)+1}],Table[{anginicial+2*Pi/(6*nparpolos)-dente/2-0.01+2Pi*y/(6*nparpolos)},{y,1,(6*nparpolos)}],Table[{anginicial+2*Pi/(6*nparpolos)-dente/2+0.01+2Pi*y/(6*nparpolos)},{y,1,(6*nparpolos)-1}](*,Table[{anginicial+2*Pi/(6*nparpolos)+dente/2-0.01+2Pi*y/(6*nparpolos)},{y,1,(6*nparpolos)}],Table[{anginicial+2*Pi/(6*nparpolos)+dente/2+0.01+2Pi*y/(6*nparpolos)},{y,0,(6*nparpolos)-1}]*)] ,1];*)
saidasobobinas=Append[saidasobobinas,{desslotsestatico,estatorrotor,Disk[centroestator,5],PlotRange->{{-110,110},{-110,110}},PlotRangeClipping->True}];
auxarq=auxarq<>"_"<>ToString[2*nparpolos]<>"p_";
elem++;)];
graftempo=Plot[{ia[x],ib[x],ic[x]},{x,0,1},PlotStyle->{{Thickness@0.02,Red},{Thickness@0.02,Blue},{Thickness@0.02,Green}},Ticks->None,AspectRatio->1,AxesLabel->{"t","currents"},Epilog->{Red,Disk[{t,ia[t]},0.05*{1,2}],Blue,Disk[{t,ib[t]},0.04*{1,2}],Green,Disk[{t,ic[t]},0.03*{1,2}]},BaseStyle->{FontSize->30}];
centrograftempo=vcentrofigura[[Length@vnparpolos+1]];
raiograftempo=vraioestator[[Length@vnparpolos+1]];
Which[tempo==True,saidai=Append[saidai,{Transparent,Line[{centrograftempo,centrograftempo+{raiograftempo,0}}],Inset[graftempo,centrograftempo,{0.5,0},180]}],True,Null];
saida=Graphics[If[sobobinas==False,saidai,saidasobobinas],PlotRange->{Automatic,{-140,140}},PlotRangeClipping->True,Background->None,ImageSize->0.8 1280];
(*saida=ColorReplace[saida,Magenta];*)
If[gerafig==True,Export[NotebookDirectory[]<>"campos2"<>auxarq<>StringTake["000"<>ToString[Round[t/(Pi/12/omega)//N]],-3]<>".png",saida,ImageResolution->300,Background->None],Null];
If[gerafig==True,Export[NotebookDirectory[]<>"campos2"<>auxarq<>StringTake["000"<>ToString[Round[t/(Pi/12/omega)//N]],-3]<>".svg",saida,ImageResolution->300,Background->None],Null];
(*saida=GraphicsGrid[{saida}];*)
saida),{t,0,2.Pi/omega,Pi/12./omega,AnimationRate->0.05},{gerafig,{False,True}},{figima,{False,True}},{sobobinas,{False,True}},{{tempo,True},{False,True}},{{mostralinhas,True},{False,True}},(*AnimationRate->If[gerafig==True,1/5,1],*)AppearanceElements->"All",TrackedSymbols:>{t}
,Initialization:>(
H[{x0_,y0_},corr_,{xi_,yi_}]:=(
corr/(2*Pi)*((xi-x0)+I*(yi-y0))/((xi-x0)^2+(yi-y0)^2));
H2[{x0_,y0_},corr_,xyi_]:=(
Module[{saida,c,r},(
saida=0;
For[c=1,c≤Length[corr],c++,(
r=(x0-xyi[[c,1]])^2+(y0-xyi[[c,2]])^2;
saida=saida+corr[[c]]/(2*Pi)*(-(y0-xyi[[c,2]])+I*(x0-xyi[[c,1]]))/If[r≠0,r^2,Infinity])];
(*Se a distância entre os pontos for zero, transformar a distância em infinito para fazer o campo ser zero*)
saida)]);
slot[{x_,y_},s_,r_:1]:=(
{Disk[{x,y},r],Black,Circle[{x,y},r],
Which[
s==1,Disk[{x,y},0.25*r],
s==-1,{Line[{{x,y}+r*{-Cos[Pi/4],-Sin[Pi/4]},{x,y}+r*{Cos[Pi/4],Sin[Pi/4]}}],Line[{{x,y}+r*{-Cos[Pi/4],Sin[Pi/4]},{x,y}+r*{Cos[Pi/4],-Sin[Pi/4]}}]},
s==0,{}]});
slot2[xy_,s_,r_:1]:=((*xy é um vetor de vetores{x,y}, s é um vetor de sentidos (1, para fora, -1, para dentro) com a mesma quantidade de termos {x,y} do vetor xy*)
Module[{saida,c},
(saida={};
For[c=1,c≤Length[xy],c++,(
saida=Append[saida,Disk[xy[[c]],r]];saida=Append[saida,{Black,Circle[xy[[c]],r],Which[s[[c]]==1,Disk[xy[[c]],0.25*r],s[[c]]==-1,{Line[{xy[[c]]+r*{-Cos[Pi/4],-Sin[Pi/4]},xy[[c]]+r*{Cos[Pi/4],Sin[Pi/4]}}],Line[{xy[[c]]+r*{-Cos[Pi/4],Sin[Pi/4]},xy[[c]]+r*{Cos[Pi/4],-Sin[Pi/4]}}]},
s[[c]]==0,{}]}];)];
saida)]);
gH2[xy_,h_]:=((*xy é um vetor de vetores{x,y}, h é um vetor de campos, com a mesma quantidade de termos do vetor xy*)
Module[{saida,c},
(saida={};
For[c=1,c≤Length[xy],c++,(
saida=If[Chop[Abs[h[[c]]]]>0,Append[saida,Arrow[{xy[[c]],xy[[c]]+{Re[h[[c]]],Im[h[[c]]]}}]],saida];);
];
saida)]);
vu[x_]:=({Cos[x],Sin[x]}//N);
(*rest[x_,r1_,r2_,n_,dente_,ang_]:=((*calcula as ranhuras do estator*)raio=If[Between[Mod[x-ang,(2*Pi/n)],{dente/2,2*Pi/n-dente/2}],r2,r1]);*)
rodadentada[centro_,n_,r1_,r2_,dente_,ang_]:=Module[{temp},(
(* centro=coordenada do centro, n=numero de dentes, r1=raio fora do dente, r2=raio dentro do dente, dente=tamanho do arco do dente, ang=angulo inicial do 1o dente. *)
temp={};
Do[(
temp=Append[temp,{
Line[{centro+r1*{Cos[ang+(x-1)*2*Pi/n],Sin[ang+(x-1)*2*Pi/n]},centro+r2*{Cos[ang+(x-1)*2*Pi/n],Sin[ang+(x-1)*2*Pi/n]}}],
Circle[centro,r2,{ang+(x-1)*2*Pi/n,dente+ang+(x-1)*2*Pi/n}],
Line[{centro+r1*{Cos[dente+ang+(x-1)*2*Pi/n],Sin[dente+ang+(x-1)*2*Pi/n]},centro+r2*{Cos[dente+ang+(x-1)*2*Pi/n],Sin[dente+ang+(x-1)*2*Pi/n]}}],
Circle[centro,r1,{dente+ang+(x-1)*2*Pi/n,ang+(x)*2*Pi/n}]
}
];
),{x,1,n}];
temp
)];
(*centroestator={0,0};
raioestator=100;*)
$HistoryLength=0;
omega=2*Pi*1;
imax=1;(*amplitude da corrente*)
ia[x_]:=imax*Cos[omega*x];
ib[x_]:=imax*Cos[omega*x-2*Pi/3];
ic[x_]:=imax*Cos[omega*x+2*Pi/3];
ima2p=ImageReflect[ImageReflect[,Top->Bottom],Left->Right];
ima4p=;
ima6p=Blend[{,Transparent},0.6];
ima8p=Blend[{,Transparent},0.6];
noima=Graphics[{}];
(*gerafig=True;*)
)],1500,Alignment->Center]

Animation functionality of beamer package for LaTeX

({{  }, {}})

Reactive power (VAr) and power factor (pf) for alternate-current circuits

Sinusoidal voltage and current with different phase angles

Instantaneous power p(t)=voltage(t) * current(t)

Row[{
        Column[{"Current peak lagging", "voltage peak", " (inductive)", " ", Plot[{100 Cos[2. Pi 60 t + 0.2], 35 Cos[2. Pi 60 t + 0.2 - ArcCos[0.6]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle ->  {{Thickness[0.01], Red}, {Thickness[0.01], Purple}}, BaseStyle -> {FontSize -> 14, Bold}, AxesLabel -> {"t", "\!\(\*
StyleBox[\"v\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"(\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"t\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\")\",\nFontColor->RGBColor[1, 0, 0]]\),\!\(\*
StyleBox[\"i\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)\!\(\*
StyleBox[\"(\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)\!\(\*
StyleBox[\"t\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)\!\(\*
StyleBox[\")\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)"},ImageSize->300]}]
        , Spacer[160],
        , Column[{"Current peak in phase", "with voltage peak", "(resistive)", " ", Plot[{100 Cos[2. Pi 60 t + 0.2], 35 Cos[2. Pi 60 t + 0.2 - ArcCos[1.]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle -> {{Thickness[0.01], Red}, {Thickness[0.01], Purple}}, BaseStyle -> {FontSize -> 14, Bold}, AxesLabel -> {"t", "\!\(\*
StyleBox[\"v\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"(\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\"t\",\nFontColor->RGBColor[1, 0, 0]]\)\!\(\*
StyleBox[\")\",\nFontColor->RGBColor[1, 0, 0]]\),\!\(\*
StyleBox[\"i\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)\!\(\*
StyleBox[\"(\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)\!\(\*
StyleBox[\"t\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)\!\(\*
StyleBox[\")\",\nFontColor->RGBColor[0.5, 0, 0.5]]\)"},ImageSize->300]}]
        }, BaseStyle -> {FontFamily -> "Baskerville"}]

Row[{
      Column[{"Instantaneous power", "may be on reverse direction,", "source ↔ load", " ", Plot[{100 Cos[2. Pi 60 t + 0.2]*35 Cos[2. Pi 60 t + 0.2 - ArcCos[0.6]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle -> {Thickness[0.01]}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "p(t)"}, PlotRange -> {-1000, 3500},ImageSize->300]}]
      , Spacer[160],
      , Column[{"Instantaneous power", "always from source to load", " ", " ", Plot[{100 Cos[2. Pi 60 t + 0.2]*35 Cos[2. Pi 60 t + 0.2 - ArcCos[1.]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle -> {Thickness[0.01]}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "p(t)"}, PlotRange -> {-1000, 3500},ImageSize->300]}]
      }, BaseStyle -> {FontFamily -> "Baskerville"}]

If a capacitive element is added to the circuit:

Row[{
            Column[{" "," ","Inductive current", " ", Plot[{100 Cos[2. Pi 60 t + 0.2], 35 Cos[2. Pi 60 t + 0.2 - ArcCos[0.6]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle ->  {{Thickness[0.005], Red}, {Thickness[0.007], Purple}}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "v(t),i(t)"},ImageSize->300]}]
      , Spacer[100]
      , Column[{" "," ", "Capacitive current"," ", Plot[{100 Cos[2. Pi 60 t + 0.2], 20 Cos[2. Pi 60 t + 0.2 + ArcCos[0]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle ->  {{Thickness[0.005], Red}, {Thickness[0.007], Darker[Green, 0.4]}}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "v(t),i(t)"},ImageSize->300]}]
      , Spacer[100]
      , Column[{"Sum of inductive and capacitive currents:", "• current phase tends to voltage phase", "• decreased amplitude", " ", Plot[{100 Cos[2. Pi 60 t + 0.2], 35 Cos[2. Pi 60 t + 0.2 - ArcCos[0.6]], 20 Cos[2. Pi 60 t + 0.2 + ArcCos[0]], 20 Cos[2. Pi 60 t + 0.2 + ArcCos[0]] + 35 Cos[2. Pi 60 t + 0.2 - ArcCos[0.6]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle ->  {{Thickness[0.005], Red}, {Thickness[0.007], Dashing[{0.005, 0.01}], Purple}, {Thickness[0.007], Dashing[{0.005, 0.01}], Darker[Green, 0.4]}, {Thickness[0.008], Orange}}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "v(t),i(t)"},ImageSize->300]}]
            }, BaseStyle -> {FontFamily -> "Baskerville"}]

Row[{
        Column[{"Instantaneous power", " ", Plot[{100 Cos[2. Pi 60 t + 0.2]* 35 Cos[2. Pi 60 t + 0.2 - ArcCos[0.6]], 0.5*100*35*0.6}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle -> {{Thickness[0.01], ColorData["DarkRainbow", 0]}}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "p(t)"}, PlotRange -> {-1100, 3500},ImageSize->300]}]
  , Spacer[100]
  , Column[{"Instantaneous power", " ", Plot[{100 Cos[2. Pi 60 t + 0.2]* 20 Cos[2. Pi 60 t + 0.2 + ArcCos[0]]}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle -> {{Thickness[0.01], ColorData["DarkRainbow", 0]}}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "p(t)"}, PlotRange -> {-1100, 3500},ImageSize->300]}]
  , Spacer[100]
  , Column[{"Instantaneous power", " ", Plot[{100 Cos[2. Pi 60 t + 0.2]*(20 Cos[2. Pi 60 t + 0.2 + ArcCos[0]] + 35 Cos[2. Pi 60 t + 0.2 - ArcCos[0.6]]), 0.5*100*35*0.6}, {t, 0, 4. Pi/(2. Pi 60)}, Ticks -> None, PlotStyle ->  {{Thickness[0.01], ColorData["DarkRainbow", 0]}}, BaseStyle -> {FontSize -> 28, Bold}, AxesLabel -> {"t", "p(t)"}, PlotRange -> {-1100, 3500},ImageSize->300]}]
        }, BaseStyle -> {FontFamily -> "Baskerville"}]

Phasor representation for cosine voltages

nciclostotal=5;
Pane[expfasor=Animate[
(
explain[t1_,t2_,g_]:=(
If[tfinal≥t1&&tfinal≤t2,g,Null]);

V1=100;V2=50;thetaV1=25.Degree;thetaV2=-35.Degree;
cores={ColorData[97,1],ColorData[97,2],ColorData[97,3]};
auxAltura=440;auxSeta=10;

nciclostotal=5.;
tvetores1=2.5/60-thetaV1/(2.Pi 60 );
tvetores2=2.5/60-thetaV2/(2.Pi 60 );
tvetores3=3.0/60-ArcTan@((V1 Sin@thetaV1+V2 Sin@thetaV2)/(V1 Cos@thetaV1+V2 Cos@thetaV2))/(2.Pi 60 );

GraphicsRow[{
Plot[{
V1 Cos[2.Pi 60 t+thetaV1]
,V2 Cos[2. Pi 60 t+thetaV2]
,explain[0.015,tfinal,V1 Cos[2.Pi 60 t+thetaV1]+V2 Cos[2. Pi 60 t+thetaV2]]
}
,{t,0.,tfinal},Epilog->{Text[Row[{"v(t) - Voltages along time, with the same frequency"},BaseStyle->{FontSize->20}],{0.001,V1+V2},{-1,1}],AbsolutePointSize[15],cores[[1]],Point[{tfinal,V1 Cos[2.Pi 60 tfinal+thetaV1]}]
,cores[[2]],Point[{tfinal,V2 Cos[2. Pi 60 tfinal+thetaV2]}]
,explain[0.015,tfinal,{cores[[3]],Point[{tfinal,V1 Cos[2.Pi 60 tfinal+thetaV1]+V2 Cos[2. Pi 60 tfinal+thetaV2]}]}]
,explain[0.01,0.016,{Text[Panel[Column[{"Sum of voltages"},Alignment->Center,BaseStyle->{FontSize->20}],Background->Lighter[cores[[3]],0.5]],{0.015,60},{-1,-1}]}]
,With[{t=0.0045},explain[t,tfinal,{cores[[1]],Text[Style["(Subscript[v, 1])(t)",{24,Bold}],{t,V1 Cos[2.Pi 60 t+thetaV1]},{1,1}]}]]
,With[{t=0.0045},explain[t,tfinal,{cores[[2]],Text[Style["(Subscript[v, 2])(t)",{24,Bold}],{t,V2 Cos[2.Pi 60 t+thetaV2]},{-1,-1}]}]]
,With[{t=0.018},explain[t,tfinal,{cores[[3]],Text[Style["(Subscript[v, 1])(t)+(Subscript[v, 2])(t)",{24,Bold}],{t,V1 Cos[2.Pi 60 t+thetaV1]+V2 Cos[2.Pi 60 t+thetaV2]},{-1,-1}]}]]
}
,PlotRange->{{-0.001,nciclostotal/60+0.001},{-V1-V2,V1+V2}},Ticks->None,AxesLabel->{"t"},ImageSize->{Automatic,auxAltura},BaselinePosition->{{0,0},Center},PlotRangeClipping->True,BaseStyle->{FontSize->20},PlotStyle->{{Thickness[0.0035],cores[[1]]},{Thickness[0.0035],cores[[2]]},{Thickness[0.0035],cores[[3]]}}]
,If[tfinal≥0.022
,Graphics[{
Line[{{0,-V1-V2},{0,V1+V2}}]
,Line[{{V1+V2,0},{-V1-V2,0}}]
,Text[Style["Cosines axis · (Sqrt[2])",{FontSize->18}],{0+6,V1+V2-4},{-1,1}],Text[Style["Sines axis· (Sqrt[2])",{FontSize->18}],{-V1-V2+10,4},{0,-1}],{
explain[0.026,tfinal,{AbsolutePointSize[15]
,cores[[1]],Point[{0,V1 Cos[2.Pi 60 tfinal+thetaV1]}]
,cores[[2]],Point[{0,V2 Cos[2. Pi 60 tfinal+thetaV2]}]
,cores[[3]],Point[{0,V1 Cos[2.Pi 60 tfinal+thetaV1]+V2 Cos[2. Pi 60 tfinal+thetaV2]}]}]
,explain[tvetores1,tfinal,{cores[[1]],{Thickness[0.005],Arrow[{{0,0},{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]}}]},Dashed,Line[{{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]},{0,V1 Cos[2.Pi 60 tfinal+thetaV1]}}]
}]
,explain[tvetores2,tfinal,{cores[[2]],{Thickness[0.005],Arrow[{{0,0},{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]}}]},Dashed,Line[{{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]},{0,V2 Cos[2.Pi 60 tfinal+thetaV2]}}]
}]
,explain[tvetores3,tfinal,{cores[[3]],{Thickness[0.005],Arrow[{{0,0},{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]}+{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]}}]}
,Dashed,Line[{{0,V1 Cos[2.Pi 60 tfinal+thetaV1]}+{0,V2 Cos[2.Pi 60 tfinal+thetaV2]},{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]}+{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]}}]
,Dashed,Lighter[Black,0.8],Line[{{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]},{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]}+{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]}}]
,Line[{{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]},{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]}+{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]}}]
}]
,explain[0.022,0.027,{Text[Panel[Column[{"If we draw the ","instantaneous","voltage in the","cosine axis ..."},Alignment->Center,BaseStyle->{FontSize->18}],Spacer[10],Background->LightPink],{-10,150},{1,1}]}]
,explain[0.036,0.043,{Text[Panel[Column[{"... the instantaneous","position coincide","with the projection","of a rotating vector." },Alignment->Center,BaseStyle->{FontSize->18}],Background->LightPink],{-10,-10},{1,1}]}]
,explain[0.06,0.07,{Text[Panel[Column[{"Vector of the ","sum of cosines","is the sum of","the other vectors." },Alignment->Center,BaseStyle->{FontSize->18}],Background->LightPink],{-15,-110},{1,-1}]}]
,explain[nciclostotal/60,tfinal,{
Text[Style["(Subscript[(OverDot[V]), 1])",{cores[[1]],24,Bold}] ,{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]},{1,-1}]
,Text[Style["(Subscript[(OverDot[V]), 2])",{cores[[2]],24,Bold}] ,{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]},{-1,-1}]
,Text[Style["(Subscript[(OverDot[V]), 1])+(Subscript[(OverDot[V]), 2])",{cores[[3]],24,Bold}] ,{-V1 Sin[2.Pi 60 tfinal+thetaV1],V1 Cos[2.Pi 60 tfinal+thetaV1]}+{-V2 Sin[2.Pi 60 tfinal+thetaV2],V2 Cos[2.Pi 60 tfinal+thetaV2]},{1,-1}]
,Text[Panel[Column[{"Arithmetic operations may be","applied to","",Row[{"phasors =    ",Column[{"• vectors for t = 0, T, 2T, ... ;","• scaled by \!\(\*FractionBox[\(\(1\)\(\\ \)\), SqrtBox[\(2\)]]\) (rms value)"}]}]},Alignment->Left,BaseStyle->{FontSize->18}],Background->LightPink],{0,-25},{0,1}]
}]
}
},ImageSize->{Automatic,auxAltura},BaselinePosition->{{0,0},Center},BaseStyle->{FontSize->24}]
,Graphics[{Transparent,Rectangle[2{-V1-V2,V1+V2}]}]]
},Spacings->0,ItemAspectRatio->{Automatic,Automatic,1},ImageSize->1.1 1280,Frame->All,FrameStyle->Opacity[0]]
)
,{tfinal,1./(60*360),5./60,1./(60*360)},AnimationRate->0.003,AnimationRepetitions->1,AnimationRunning->False],1500,Alignment->Center]

Power factor correction

formatar[y_, digdec_: 2, simb_: 0] := (
  Module[{simbcomp, compantes, x}, (
    (*'simbcomp' indica o símbolo de sqrt[-1],default=j;'compantes' indica se o símbolo de complexo vem antes (True) ou depois (False) do valor da parte imaginária simb=0,simbcom=j,comapantes=True,simb=1,simbcom=i,comapantes=True,simb=2,simbcom=J,comapantes=True,simb=3,simbcom=I,comapantes=True,simb=4,simbcom=j,comapantes=False,simb=5,simbcom=i,comapantes=False,simb=6,simbcom=J,comapantes=False,simb=7,simbcom=I,comapantes=False,*)
    x = Chop[N[y]];
    simbcomp = Switch[simb, 0, "j", 1, "i", 2, "J", 3, "I", 4, "j", 5, "i", 6, "J", 7, "I"]; compantes = Switch[simb, 0, True, 1, True, 2, True, 3, True, 4, False, 5, False, 6, False, 7, False]; ToString[If[digdec == 0, NumberForm[N[Round[Re[x]]], 0], NumberForm[N[Round[Re[x], 10^(-digdec)]], {10, digdec}]]] <> If[Im[x] != 0, If[Im[x] > 0, "+", "-"] <> If[compantes == True, simbcomp, ""] <> ToString[If[digdec == 0, NumberForm[N[Round[Abs[Im[x]]]], 0], NumberForm[N[Round[Abs[Im[x]], 10^(-digdec)]], {10, digdec}]]], ""] <> If[compantes == False, simbcomp, ""])]);

polar[x_, digabs_: 2, digangle_: 1] := ToString[formatar[Abs[x], digabs]] <> " ∠ " <> ToString[formatar[Arg[x]/Pi*180, digangle]] <> "°";

paralelo[x_] := (soma = 0;
  saida = If[Length[x] == 0, x, (For[i = 1, i <= Length[x], i++, soma = soma + 1/x[[i]]];
     soma = 1/soma)]);

rectd[mod_, ang_] := (saida = mod*Cos[ang/180*Pi] + I*mod*Sin[ang/180*Pi]);

PosLabel[p1_, comprimento_, angrot_, distancia_: 0.05, OptionsPattern[]] := (Options[PosLabel] = {ajustex -> 0, ajustey -> 0}; Module[{ajx, ajy, meio, coordtexto}, ajx = OptionValue[ajustex]; ajy = OptionValue[ajustey]; meio = p1 + comprimento/2*{-Sin[angrot], Cos[angrot]}; coordtexto = Switch[angrot, Pi/2, meio + {0, distancia*comprimento}, -Pi/2, meio + {0, -distancia*comprimento}, _, meio + {distancia*comprimento/Cos[angrot], 0}] + {ajx, ajy}]);

Resistor[p1_, p2o_, texto_, OptionsPattern[]] := (Options[Resistor] = {ocupacao -> 0.7, proporcao -> 0.3, numerovoltas -> 3, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0}; Module[{k1, k2, k3, distancia, estilo, ajustelabelx2, ajustelabely2, c, comprimento, angrot, p2, compres, largres, ptosres, imres}, (
    k1 = OptionValue[ocupacao];
    k2 = OptionValue[proporcao];
    k3 = OptionValue[numerovoltas];
    distancia = OptionValue[distlabel];
    estilo = OptionValue[estilotexto];
    ajustelabelx2 = OptionValue[ajustelabelx];
    ajustelabely2 = OptionValue[ajustelabely];
    comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
    angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2;
    p2 = {p1[[1]], p1[[2]] + comprimento};
    compres = comprimento*k1;
    largres = compres*k2; ptosres = {p1};
    ptosres = Append[ptosres, p1 + (0.5 - k1/2)*(p2 - p1)];
    ptosres = Append[ptosres, ptosres[[Length[ptosres]]] + {-largres/2, compres/4/k3}]; For[c = 1, c <= 2*k3 - 1, c++, ptosres = Append[ptosres, ptosres[[Length[ptosres]]] + {If[OddQ[c], 1, -1]*largres, compres/2/k3}];]; ptosres = Append[ptosres, ptosres[[Length[ptosres]]] + {-largres/2, compres/4/k3}]; ptosres = Append[ptosres, p2]; imres = GraphicsGroup[{Line[ptosres]}]; imres = GeometricTransformation[imres, RotationTransform[angrot, p1]]; imres = {imres, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]})]);
Resistor::usage = "[coordenada_inicial,coordenada_final,label,opcionais(ocupacao->0.7, proporcao->0.3, distlabel->0.4, estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

Indutor[p1_, p2o_, texto_, OptionsPattern[]] := (Options[Indutor] = {ocupacao -> 0.7, numerovoltas -> 4, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0}; Module[{k4, k5, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, angrot, p2, compind, termind1, termind2, corpoind, c, centro, imind}, k4 = OptionValue[ocupacao];
       k5 = OptionValue[numerovoltas];
       distancia = OptionValue[distlabel];
       estilo = OptionValue[estilotexto];
       ajustelabelx2 = OptionValue[ajustelabelx];
       ajustelabely2 = OptionValue[ajustelabely];
       comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2;
       p2 = {p1[[1]], p1[[2]] + comprimento};
       compind = comprimento*k4;
       termind1 = {p1, p1 + (0.5 - k4/2)*(p2 - p1)};
       termind2 = {p1 + (0.5 + k4/2)*(p2 - p1), p2};
       corpoind = {};
       For[c = 1, c <= k5, c++, centro = p1 + (0.5 - k4/2)*(p2 - p1) + {0, compind/2/k5*(2*c - 1)};
         corpoind = GraphicsGroup[{corpoind, Circle[centro, comprimento*k4/2/k5, {-Pi/2, Pi/2}]}]];
       imind = GraphicsGroup[{Line[termind1], corpoind, Line[termind2]}];
       imind = GeometricTransformation[imind, RotationTransform[angrot, p1]];
       imind = {imind, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}]);
Indutor::usage = "[coordenada_inicial,coordenada_final,texto,opcionais(ocupacao->0.7,numerovoltas->4,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

Capacitor[p1_, p2o_, texto_, OptionsPattern[]] := (Options[Capacitor] = {ocupacao -> 0.1, proporcao -> 5, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0};
     Module[{k7, k8, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, angrot, p2, termcap1, termcap2, corpocap1, corpocap2, imcap}, k7 = OptionValue[ocupacao];
       k8 = OptionValue[proporcao];
       distancia = OptionValue[distlabel];
       estilo = OptionValue[estilotexto];
       ajustelabelx2 = OptionValue[ajustelabelx];
       ajustelabely2 = OptionValue[ajustelabely];
       comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2;
       p2 = {p1[[1]], p1[[2]] + comprimento};
       termcap1 = {p1, p1 + (0.5 - k7/2)*(p2 - p1)};
       termcap2 = {p1 + (0.5 + k7/2)*(p2 - p1), p2};
       corpocap1 = {p1 + (0.5 - k7/2)*(p2 - p1) - {k8*comprimento*k7/2, 0}, p1 + (0.5 - k7/2)*(p2 - p1) + {k8*comprimento*k7/2, 0}};
       corpocap2 = {p1 + (0.5 + k7/2)*(p2 - p1) - {k8*comprimento*k7/2, 0}, p1 + (0.5 + k7/2)*(p2 - p1) + {k8*comprimento*k7/2, 0}};
       imcap = GraphicsGroup[{Line[termcap1], Line[corpocap1], Line[corpocap2], Line[termcap2]}];
       imcap = GeometricTransformation[imcap, RotationTransform[angrot, p1]];
       imcap = {imcap, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}]);
Capacitor::usage = "[coordenada_inicial,coordenada_final,texto,opcionais(ocupacao->0.7, proporcao->0.3, distlabel->0.4, estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

FonteCA[p1_, p2o_, texto_, OptionsPattern[]] := (Options[FonteCA] = {ocupacao -> 0.25, distlabel -> 0.4, estilotexto -> {}, ajustelabelx -> 0, ajustelabely -> 0};
     Module[{k9, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, angrot, p2, termfonte1, termfonte2, centrofonte, raiofonte, c1, c2, centroarcosenoide1, centroarcosenoide2, teta, corpofonte, imfonte}, k9 = OptionValue[ocupacao];
       distancia = OptionValue[distlabel];
       estilo = OptionValue[estilotexto];
       ajustelabelx2 = OptionValue[ajustelabelx];
       ajustelabely2 = OptionValue[ajustelabely];
       comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2;
       p2 = {p1[[1]], p1[[2]] + comprimento};
       termfonte1 = {p1, p1 + (0.5 - k9/2)*(p2 - p1)};
       termfonte2 = {p1 + (0.5 + k9/2)*(p2 - p1), p2};
       centrofonte = (p1 + p2)/2;
       raiofonte = k9/2*comprimento;
       c1 = 0.3; c2 = 0.1;
       centroarcosenoide1 = centrofonte + raiofonte*{c1, c2};
       centroarcosenoide2 = centrofonte - raiofonte*{c1, c2};(*para fazer a senoide*)raioarcosenoide = raiofonte*Sqrt[c1^2 + c2^2];
       teta = ArcCos[raiofonte*c2/raioarcosenoide];(*para fazer a senoide*)corpofonte = GraphicsGroup[{Circle[centrofonte, raiofonte], Circle[centroarcosenoide1, raioarcosenoide, {3*Pi/2 - teta, 3*Pi/2 + teta}], Circle[centroarcosenoide2, raioarcosenoide, {Pi/2 - teta, Pi/2 + teta}]}];
       imfonte = GraphicsGroup[{Line[termfonte1], corpofonte, Line[termfonte2]}];
       imfonte = GeometricTransformation[imfonte, RotationTransform[angrot, p1]];
       imfonte = {imfonte, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}]);
FonteCA::usage = "[coordenada_inicial,coordenada_final,label,opcionais(ocupacao->0.25,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

Impedancia[p1_, p2o_, texto_, OptionsPattern[]] := (Options[Impedancia] = {ocupacao -> 0.6, proporcao -> 0.3, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0};
     Module[{k7, k8, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, angrot, p2, termimp1, termimp2, corpoimp1, corpoimp2, corpoimp3, corpoimp4, imimp}, k7 = OptionValue[ocupacao];
       k8 = OptionValue[proporcao];
       distancia = OptionValue[distlabel];
       estilo = OptionValue[estilotexto];
       ajustelabelx2 = OptionValue[ajustelabelx];
       ajustelabely2 = OptionValue[ajustelabely];
       comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2;
       p2 = {p1[[1]], p1[[2]] + comprimento};
       termimp1 = {p1, p1 + (0.5 - k7/2)*(p2 - p1)};
       termimp2 = {p1 + (0.5 + k7/2)*(p2 - p1), p2};
       corpoimp1 = {p1 + (0.5 - k7/2)*(p2 - p1) - {k8*comprimento*k7/2, 0}, p1 + (0.5 - k7/2)*(p2 - p1) + {k8*comprimento*k7/2, 0}};
       corpoimp2 = {p1 + (0.5 + k7/2)*(p2 - p1) - {k8*comprimento*k7/2, 0}, p1 + (0.5 + k7/2)*(p2 - p1) + {k8*comprimento*k7/2, 0}};
       corpoimp3 = {p1 + (0.5 - k7/2)*(p2 - p1) - {k8*comprimento*k7/2, 0}, p1 + (0.5 + k7/2)*(p2 - p1) - {k8*comprimento*k7/2, 0}};
       corpoimp4 = {p1 + (0.5 - k7/2)*(p2 - p1) + {k8*comprimento*k7/2, 0}, p1 + (0.5 + k7/2)*(p2 - p1) + {k8*comprimento*k7/2, 0}};
       imimp = GraphicsGroup[{Line[termimp1], Line[corpoimp1], Line[corpoimp2], Line[corpoimp3], Line[corpoimp4], Line[termimp2]}];
       imimp = GeometricTransformation[imimp, RotationTransform[angrot, p1]];
       imimp = {imimp, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}]);
Impedancia::usage = "[coordenada_inicial,coordenada_final,label,opcionais(ocupacao->0.6,proporcao->0.3,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

ArcoTensao[p1_, p2o_, texto_, OptionsPattern[]] := (Options[ArcoTensao] = {sentido -> "hor", proporcao -> 0.15, proporcaoseta -> 1, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0};
     Module[{sentidox, k1, proporcaosetax, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, h, angrot, p2, larg, r, teta, centro, cabecaseta, imarco}, sentidox = OptionValue[sentido];
       k1 = OptionValue[proporcao];
       proporcaosetax = OptionValue[proporcaoseta];
       distancia = OptionValue[distlabel];
       estilo = OptionValue[estilotexto];
       ajustelabelx2 = OptionValue[ajustelabelx];
       ajustelabely2 = OptionValue[ajustelabely];
       comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       h = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       angrot = Arg[(p2o[[1]] - p1[[1]]) + I (p2o[[2]] - p1[[2]])] - π/2;
       p2 = {p1[[1]], p1[[2]] + h}; larg = k1*h;
       r = (h^2/4 + larg^2)/(2 larg); teta = ArcSin[h/(2 r)];
       centro = {p1[[1]] + If[sentidox == "hor", r Cos[teta], -r Cos[teta]], p1[[2]] + r Sin[teta]};
       cabecaseta = GeometricTransformation[Line[{{p2[[1]] - 0.03*proporcaosetax*h, p2[[2]] - 0.1*proporcaosetax*h}, p2, {p2[[1]] + 0.03*proporcaosetax*h, p2[[2]] - 0.1*proporcaosetax*h}}], RotationTransform[If[sentidox == "hor", -teta, teta], p2]];
       imarco = {Circle[centro, r, If[sentidox == "hor", {teta + π, -teta + π}, {-teta, teta}]], cabecaseta};
       imarco = GeometricTransformation[imarco, RotationTransform[angrot, p1]];
       imarco = {imarco, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}]);
ArcoTensao::usage = "[coordenada_inicial,coordenada_final,label,optionais(sentido->\"hor\"(aspas duplas),proporcao->0.15,proporcaoseta->1,distlabel->0.4, estilo->\"None\",ajustelabelx  ->0,ajustelabely->0)]";

FonteCC[p1_, p2o_, texto_, OptionsPattern[]] := (Options[FonteCC] = {ocupacao -> 0.1, proporcao -> 5, razaopolonegpos -> 0.4, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0};
     Module[{k7, k8, k9, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, angrot, p2, termfonteCC1, termfonteCC2, corpofonteCC1, corpofonteCC2, imfonteCC}, k7 = OptionValue[ocupacao];
       k8 = OptionValue[proporcao];
       k9 = OptionValue[razaopolonegpos];
       distancia = OptionValue[distlabel];
       estilo = OptionValue[estilotexto];
       ajustelabelx2 = OptionValue[ajustelabelx];
       ajustelabely2 = OptionValue[ajustelabely];
       comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2;
       p2 = {p1[[1]], p1[[2]] + comprimento};
       termfonteCC1 = {p1, p1 + (0.5 - k7/2)*(p2 - p1)};
       termfonteCC2 = {p1 + (0.5 + k7/2)*(p2 - p1), p2};
       corpofonteCC1 = {p1 + (0.5 - k7/2)*(p2 - p1) - {k9*k8*comprimento*k7/2, 0}, p1 + (0.5 - k7/2)*(p2 - p1) + {k9*k8*comprimento*k7/2, 0}};
       corpofonteCC2 = {p1 + (0.5 + k7/2)*(p2 - p1) - {k8*comprimento*k7/2, 0}, p1 + (0.5 + k7/2)*(p2 - p1) + {k8*comprimento*k7/2, 0}};
       imfonteCC = GraphicsGroup[{Line[termfonteCC1], Line[corpofonteCC1], Line[corpofonteCC2], Line[termfonteCC2]}];
       imfonteCC = GeometricTransformation[imfonteCC, RotationTransform[angrot, p1]];
       imfonteCC = {imfonteCC, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}]);
FonteCC::usage = "[coordenada_inicial,coordenada_final,label,opcionais(ocupacao->0.1,proporcao->5,razaopolonegpos->0.4,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

FonteCorrente[p1_, p2o_, texto_, OptionsPattern[]] := (Options[FonteCorrente] = {ocupacao -> 0.25, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0};
     Module[{k9, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, angrot, p2, termfontecorr1, termfontecorr2, corpofontecorr, ptosseta1, ptosseta2, imfontecorr}, k9 = OptionValue[ocupacao];
       distancia = OptionValue[distlabel];
       estilo = OptionValue[estilotexto];
       ajustelabelx2 = OptionValue[ajustelabelx];
       ajustelabely2 = OptionValue[ajustelabely];
       comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5;
       angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2;
       p2 = {p1[[1]], p1[[2]] + comprimento};
       termfontecorr1 = {p1, p1 + (0.5 - k9/2)*(p2 - p1)};
       termfontecorr2 = {p1 + (0.5 + k9/2)*(p2 - p1), p2};
       corpofontecorr = GraphicsGroup[{Circle[(p1 + p2)/2, k9/2*comprimento]}];
       ptosseta1 = {(p1 + p2)/2 - {0, k9*comprimento/3}, (p1 + p2)/2 + {0, k9*comprimento/3}};
       ptosseta2 = {ptosseta1[[2]] + {-0.1*2/3*k9*comprimento, -0.2*2/3*k9*comprimento}, ptosseta1[[2]], ptosseta1[[2]] + {0.1*2/3*k9*comprimento, -0.2*2/3*k9*comprimento}};
       imfontecorr = GraphicsGroup[{Line[termfontecorr1], corpofontecorr, Line[ptosseta1], Line[ptosseta2], Line[termfontecorr2]}];
       imfontecorr = GeometricTransformation[imfontecorr, RotationTransform[angrot, p1]];
       imfontecorr = {imfontecorr, Text[Style[texto, estilo], PosLabel[p1, comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}]);
FonteCorrente::usage = "[coordenada_inicial,coordenada_final,label,opcionais(percentual_ocupado(ocupacao->0.25,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

SetaCorrente[p1_, p2o_, texto_, OptionsPattern[]] := (Options[SetaCorrente] = {propcomeco -> 0.1, compseta -> 0.1, distseta -> 0.04, proporcaoseta -> 3, distlabel -> 0.4, estilotexto -> "None", ajustelabelx -> 0, ajustelabely -> 0}; Module[{propcomecox, compsetax, dist, propseta, distancia, estilo, ajustelabelx2, ajustelabely2, comprimento, angrot, p2, p1x, p2x, imseta, r, p1xx}, propcomecox = OptionValue[propcomeco]; compsetax = OptionValue[compseta]; dist = OptionValue[distseta]; propseta = OptionValue[proporcaoseta]; distancia = OptionValue[distlabel]; estilo = OptionValue[estilotexto]; ajustelabelx2 = OptionValue[ajustelabelx]; ajustelabely2 = OptionValue[ajustelabely]; comprimento = ((p2o[[2]] - p1[[2]])^2 + (p2o[[1]] - p1[[1]])^2)^0.5; angrot = Arg[p2o[[1]] - p1[[1]] + I*(p2o[[2]] - p1[[2]])] - Pi/2; p2 = {p1[[1]], p1[[2]] + comprimento}; p1x = p1 + {-dist*comprimento, propcomecox*comprimento}; p2x = p1x + {0, compsetax*comprimento}; imseta = {Line[{p1x, p2x}], Line[{p2x + propseta*{-0.03*compsetax*comprimento, -0.1*compsetax*comprimento}, p2x, p2x + propseta*{0.03*compsetax*comprimento, -0.1*compsetax*comprimento}}]}; imseta = GeometricTransformation[imseta, RotationTransform[angrot, p1]]; r = RotationTransform[angrot, p1]; p1xx = r[p1x]; imseta = {imseta, Text[Style[texto, estilo], PosLabel[p1xx, compsetax*comprimento, angrot, distancia, ajustex -> ajustelabelx2, ajustey -> ajustelabely2]]}])
   SetaCorrente::usage = "[coordenada_inicial,coordenada_final,label,opcionais(propcomeco-> 0.1,compseta ->0.1,distseta->0.04,proporcaoseta->3,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

filme=Pane[Manipulate[
Module[{f1,estiloRLC,estiloCorr,estiloTensao,estiloP,estiloQ,estiloFP,textofonte,textoresistor1,textoimplinha,textoindutor1,cap,reatcap1,textocapacitor1,zeq,ifonte,vcarga,vcargatexto,irl,ic,sfonte,qfontetexto,srl,prltexto,qrltexto,sc,qctexto,fp,simp,pimp,qimp,r1,l1,c1,imp1,arc1,linhas,labelfp,labelvfonte,labelvcarga,labelifonte,labelirl,labelic,labelpfonte,labelqfonte,labelprl,labelqrl,labelqc,labelpimp,labelqimp,x1cx,caixacarga,origemfasor,tamanhofasortensao,fasorvfonte,fasorvcarga,tamanhofasorcorrente,fasorirl,fasoric,fasorifonte,centromotor,motor},
(*Animate[*)
(estiloRLC={24,FontFamily->"Arial"};
estiloCorr={24,Bold,FontFamily->"Arial",Blue};
estiloTensao={24,Bold,FontFamily->"Arial",Brown};
estiloP={24,Bold,FontFamily->"Arial",Red};
estiloQ={24,Bold,FontFamily->"Arial",Darker[Green,0.5]};
estiloFP={26,FontFamily->"Arial",Bold};
textofonte=Row[{"(Subscript[(OverDot[V]), fonte]) = (",polar[fonte,1,1],") V"}];
textoresistor1=Row[{resistor1," Ω"}];
textoimplinha="("<>ToString[formatar[implinha,2]]<>") Ω";
textoindutor1=Row[{"j",reatind1," Ω"}];
cap=listacap[[passo]];
reatcap1=If[cap!=0,1/(2*Pi*60*cap)//N,Infinity];
(*labelcap={Text[Style["C = "<>ToString[formatar[cap*10^6,1]]<> " µF",estiloRLC],{17,4.5},{1,-1}]};*)
textocapacitor1=Row[{"-j",formatar[reatcap1,1]," Ω\n","C = ",formatar[cap*10^6,1], " µF"}];
zeq=implinha+paralelo[{resistor1+I*reatind1,-I*reatcap1}];
ifonte=fonte/zeq;ifontetexto=Row[{"(",polar[ifonte,1,1],")A","\n(",formatar[ifonte,1],")A"}];
vcarga=fonte-ifonte*implinha;
vcargatexto=Row[{"(Subscript[(OverDot[V]), carga]) = (",polar[vcarga,1,1],") V"}];
irl=vcarga/(resistor1+I*reatind1);irltexto=Row[{"(",polar[irl,1,1],") A","\n(",formatar[irl,1],") A"}];
ic=vcarga/(-I*reatcap1);ictexto=Row[{"(",polar[ic,1,1],") A","\n(",formatar[ic,1],") A"}];
sfonte=fonte*Conjugate[ifonte];pfontetexto=ToString[formatar[Re[sfonte],1]]<>" W";
qfontetexto=ToString[formatar[Im[sfonte],1]]<>" VAr";
srl=vcarga*Conjugate[irl];
prltexto=ToString[formatar[Re[srl],1]]<>" W";
qrltexto=ToString[formatar[Im[srl],1]]<>" VAr";
sc=vcarga*Conjugate[ic];
qctexto=ToString[formatar[Im[sc],1]]<>" VAr";
fp=Re[srl]/Abs[srl+sc];fi=Arg[srl+sc]/Pi*180;
fp=Row[{"fp = ",formatar[Re[srl]/Abs[srl+sc],2],If[Im[srl+sc]==0,"",If[Im[srl+sc]>0," ind"," cap"]]," (ϕ = ",formatar[fi,2],"°)"}];
simp=Abs[ifonte]^2*implinha;
pimp=Re[simp];pimptexto=ToString[formatar[pimp,1]]<>" W";
qimp=Im[simp];qimptexto=ToString[formatar[qimp,1]]<>" VAr";
f1=FonteCA[{90,40},{90,200},"",estilotexto->estiloTensao,ocupacao->0.2,distlabel->-0.3,ajustelabelx->-3];
r1=Resistor[{310,120},{310,200},textoresistor1,estilotexto->estiloRLC,ocupacao->0.3,distlabel->0.3,ajustelabely->-20,ajustelabelx->-7];
l1=Indutor[{310,40},{310,120},textoindutor1,estilotexto->estiloRLC, ocupacao->0.3,distlabel->0.35,ajustelabely->-20,ajustelabelx->-10];
c1=Capacitor[{210,40},{210,200},textocapacitor1,estilotexto->estiloRLC,ocupacao->0.04,proporcao->3,distlabel->-0.3,ajustelabely->-1];
imp1=If[implinha≠0,Impedancia[{90,200},{130,200},textoimplinha,estilotexto->estiloRLC,ocupacao->0.15,distlabel->-0.1,ajustelabely->7],{Line[{{90,200},{130,200}}]}];
arc1=ArcoTensao[{35,0},{35,14},"("<>polar[vcarga,2,1]<>") V", estilotexto->estiloTensao,sentido->"ahor",ajustelabelx->1,ajustelabely->3.5,proporcao->0.1];
linhas={Line[{{90,40},{310,40}}],Line[{{130,200},{310,200}}]};
labelfp={Text[Style[fp,estiloFP],{270,210},{0,-1}]};
labelvfonte={Text[Style[textofonte,estiloTensao],{80,30},{0,1}]};
labelvcarga={Text[Style[vcargatexto,estiloTensao],{270,30},{0,1}]};
labelifonte={Text[Style[ifontetexto,estiloCorr],{88,150},{1,-1}]};
labelirl={Text[Style[irltexto,estiloCorr],{305,150},{1,-1}]};
labelic={Text[Style[ictexto,estiloCorr],{205,150},{1,-1}]};
labelpfonte={Text[Style[pfontetexto,estiloP],{88,65},{1,-1}]};
labelqfonte={Text[Style[qfontetexto,estiloQ],{88,50},{1,-1}]};
labelprl={Text[Style[prltexto,estiloP],{305,65},{1,-1}]};
labelqrl={Text[Style[qrltexto,estiloQ],{305,50},{1,-1}]};
labelqc={Text[Style[qctexto,estiloQ],{205,50},{1,-1}]};
labelpimp={Text[Style[pimptexto,estiloP],{80,220},{0,-1}]};
labelqimp={Text[Style[qimptexto,estiloQ],{140,220},{0,-1}]};
x1cx=120;x2cx=345;y1cx=35;y2cx=205;
caixacarga={Gray,Dashed,Line[{{x1cx,y1cx},{x1cx,y2cx},{x2cx,y2cx},{x2cx,y1cx},{x1cx,y1cx}}]};
origemfasor={360,120};
tamanhofasortensao=65;
fasorvfonte={Brown,Arrowheads[0.02],Arrow[{origemfasor,origemfasor+tamanhofasortensao*{Cos[Arg[fonte]],Sin[Arg[fonte]]}}],Text[Style[If[implinha≠0,"(Subscript[(OverDot[V]), fonte])",""],estiloTensao],origemfasor+tamanhofasortensao*{Cos[Arg[fonte]],Sin[Arg[fonte]]}*1.3,{1,-1}]};
fasorvcarga={Brown,Arrowheads[0.02],Arrow[{origemfasor,origemfasor+tamanhofasortensao*Abs[vcarga/fonte]{Cos[Arg[vcarga]],Sin[Arg[vcarga]]}}],Text[Style[If[implinha≠0,"(Subscript[(OverDot[V]), carga])","(Subscript[(OverDot[V]), carga])=(Subscript[(OverDot[V]), fonte])"],estiloTensao],origemfasor+tamanhofasortensao*Abs[vcarga/fonte]*{Cos[Arg[vcarga]],Sin[Arg[vcarga]]-.05}*1.3,{1,1}]};
tamanhofasorcorrente=50;
fasorirl={Blue,Arrowheads[0.02],Arrow[{origemfasor,origemfasor+tamanhofasorcorrente*{Cos[Arg[irl]],Sin[Arg[irl]]}}],Text[Style[If[cap≠0,"(Subscript[(OverDot[I]), carga])","(Subscript[(OverDot[I]), carga])=(Subscript[(OverDot[I]), fonte])"],estiloCorr],origemfasor+tamanhofasorcorrente*{Cos[Arg[irl]],Sin[Arg[irl]]}*1.15]};
fasoric={Blue,Arrowheads[0.02],Arrow[{origemfasor,origemfasor+tamanhofasorcorrente*Abs[ic/irl]*{Cos[Arg[ic]],Sin[Arg[ic]]}}],Text[Style["(Subscript[(OverDot[I]), cap])",estiloCorr],origemfasor+tamanhofasorcorrente*Abs[ic/irl]*{Cos[Arg[ic]],Sin[Arg[ic]]}*1.15]};
fasorifonte={Blue,Arrowheads[0.02],Arrow[{origemfasor,origemfasor+tamanhofasorcorrente*Abs[ifonte/irl]*{Cos[Arg[ifonte]],Sin[Arg[ifonte]]}}],Text[Style[If[cap≠0,"(Subscript[(OverDot[I]), fonte])",""],estiloCorr],origemfasor+tamanhofasorcorrente*Abs[ifonte/irl]*{Cos[Arg[ifonte]],Sin[Arg[ifonte]]}*1.15,{0,-2}]};
centromotor={310,120};raiomotor=20;angulobasemotor=45;alturabasemotor=25;largurabasemotor=45;
motor={Circle[centromotor,raiomotor],Text[Style["M",{Bold,48}],centromotor,{0,0}],Line[{centromotor+raiomotor*{-Cos[angulobasemotor/180*Pi],-Sin[angulobasemotor/180*Pi]},centromotor+{-0.5*largurabasemotor,-alturabasemotor},centromotor+{0.5*largurabasemotor,-alturabasemotor},centromotor+raiomotor*{Cos[angulobasemotor/180*Pi],-Sin[angulobasemotor/180*Pi]}}],Line[{{310,200},{310,140}}],Line[{{310,40},{310,95}}],Text[Style["("<>ToString[formatar[(resistor1+I*reatind1),0]]<>")Ω",{FontFamily->"Arial",24}],{285,120},{1,0}]};
saida=Graphics[{Transparent,Line[{{0,0},{0,yframe},{xframe,yframe},{xframe,0},{0,0}}],Opacity[1],Thickness[0.003],f1,If[mostramotor==False,{r1,l1},{motor}],imp1,linhas,labelfp,labelvfonte,labelifonte,labelirl,labelpfonte,labelqfonte,labelprl,labelqrl,labelvcarga,Black,fasorvfonte,fasorvcarga,fasorirl,fasorifonte,If[implinha≠0,{labelpimp,labelqimp},Null],
If[cap≠0,{c1,labelic,labelqc,fasoric},Null],caixacarga},Background->None,ImageSize->0.85 1280,ImagePadding->0,PlotRangePadding->0];
If[gerafig==True,Export[NotebookDirectory[]<>"\\ep6_"<>StringTake["000"<>ToString[passo],-3]<>".svg",saida,ImageResolution->300,Background->None],Null];
If[gerafig==True,Export[NotebookDirectory[]<>"\\ep6_"<>StringTake["000"<>ToString[passo],-3]<>".png",saida,ImageResolution->300,Background->None],Null];
saida)],
{passo,1,nmax,1,AnimationRate->If[gerafig==True,1/5,1],Appearance->"Open"}
,Initialization:>(

fonte=231.;
resistor1=2;
reatind1=2;
(*implinha=0.22+I*0.44;*)
implinha=0;
(*primeiro item da lista se refere ao circuito sem capacitor*)
listatanteta=Tan[{ArcCos[0.75],ArcCos[0.8],ArcCos[0.85],ArcCos[0.9],ArcCos[0.92],ArcCos[0.95],ArcCos[0.98],0,-ArcCos[0.98],-ArcCos[0.95],-ArcCos[0.92],-ArcCos[0.90],-ArcCos[0.85],-ArcCos[0.80],-ArcCos[0.75],-ArcCos[0.70]}];
nmax=Length[listatanteta]+1; (*o primeiro item de 'listaxc' tem xc=infinito, para considerar o circuito sem correção*)
listaxc=(reatind1^2+resistor1^2)/(reatind1-listatanteta*resistor1);
listaxc=Insert[listaxc,Infinity,1];
listacap=1/(listaxc*2*Pi*60)//N;
gerafig=False;
mostramotor=True;
xframe=450;yframe=240;
)
],1500,Alignment->Center]
(*zeq2=paralelo[{2+I*2,-I*reatcap1}]//N;
req1=2;xeq1=2;req2=Re[zeq2];xeq2=Im[zeq2];dv1=0.9/1.05//N;dv2=0.95/1.05//N;
Solve[{(req1^2+xeq1^2)/((req1+r)^2+(xeq1+x)^2)==dv1^2,(req2^2+xeq2^2)/((req2+r)^2+(xeq2+x)^2)==dv2^2},{r,x}];*)

One step forward: creating cdf files to be distributed to students

USP uses Moodle (Modular Object-Oriented Dynamic Learning Environment) as its main plataform for teaching / learning support (eDisciplinas)

File repository, group/individual activities, general communications, multimedia content

Statistics for acess, anonymous feedback

Challenges and support for notebook/cdf development in Mathematica

Visual results and dynamic features of Mathematica are not widely known among users

Initial difficulty to create / import images for circuit drawing ⇒ custom function for sources, resistors, inductors, voltage measurements etc

Challenge to understanding dynamic features, in addition to the Manipulate function

In a few weeks students were already producing very interesting results. Nevertheless, Wolfram language learning is a necessary step to be included in the work schedule

Exchange of experiences with other users at the 2015 and 2017 Brazilian WTC

Book:  "An Elementary Introduction to the Wolfram Language"

mathematica.stackexchange.com, blog.wolfram.com

Automation fundaments classes: electrical circuits with relays and timers

With relays, timers and other discrete devices, simple automation actions can be carried out : an exhaustor that must be turned on after a door is opened, a conveyer belt that must be turned on if a box is detected and turned off when overload is detected ...

Contactor (master relay): device composed of a coil in which a electric current produces a magnetic field that moves some contacts from "open" to "closed" or from "closed" to "open"

On - delay timer: device that runs similarly to contactor, which contacts moves after a specific amount of time

Miscellaneous : push - buttons, lamps, overload sensors, fuses ...

simcont = Pane[DynamicModule[{run, edita, opera, operacaoedicao, p, pp1, pp2, lixeira, tamanho, listpreconf, listnomebobcont, listnometempon, listnomebotna, listnomebotnf, listnomebobinas, listnomelamp, listnomecargas, bobcontmodelo, temponmodelo, contnamodelo, contnfmodelo, botnamodelo, botnfmodelo, lampmodelo, fiomodelo, fusivelmodelo, contnasenstermmodelo, contnatermmodelo, contnftermmodelo, carga3fmodelo, figbarra, confconfvertices, confconfarestas, confcargas, preconfconfvertices, preconfconfarestas, preconfcargas, comentario, passox, passoy, barra, verticeF1, verticeF2, verticeP1, verticeP2, verticeP3, escolhapreconf, limitesx, limitesy,
    novosvertices, novasarestas, vertlixeira, copyConf, aux1, aux2, aux3, posvertice0, posvertice1, posvertice2, posvertice3},
   ((* Lista de circuitos pré-configurados *)
    
    
    (*Pré-configurações em Thu 29 Mar 2018 11-05-42*)(*Circuito 1:*)preconfconfvertices[1] = {{1, {180., 660.}}, {2, {180., 510.}}, {3, {390., 450.}}, {4, {390., 420.}}, {5, {390., 390.}}, {6, {225., 570.}}, {7, {225., 510.}}, {10, {180., 510.}}, {11, {210., 510.}}, {12, {210., 510.}}, {13, {225., 510.}}, {14, {225., 600.}}, {15, {225., 585.}}, {16, {255., 585.}}, {17, {255., 570.}}, {18, {255., 600.}}, {19, {255., 585.}}, {20, {225., 585.}}, {21, {225., 570.}}, {22, {225., 570.}}, {23, {255., 570.}}, {24, {225., 645.}}, {25, {225., 630.}}, {26, {255., 615.}}, {27, {255., 600.}}, {28, {225., 615.}}, {29, {225., 600.}}, {30, {225., 630.}}, {31, {225., 615.}}, {32, {225., 615.}}, {33, {255., 615.}}, {34, {225., 660.}}, {35, {225., 645.}}, {36, {180., 660.}}, {37, {210., 660.}}, {38, {210., 660.}}, {39, {225., 660.}}, {40, {540., 285.}}, {41, {510., 300.}}, {42, {540., 300.}}, {43, {570., 300.}}, {44, {540., 345.}}, {45, {540., 330.}}, {46, {450., 345.}}, {47, {450., 330.}}, {48, {630., 345.}}, {49, {630., 330.}}, {50, {630., 330.}}, {51, {630., 300.}}, {52, {450., 330.}}, {53, {450., 300.}}, {54, {540., 330.}}, {55, {540., 300.}}, {56, {540., 420.}}, {57, {540., 345.}}, {58, {630., 390.}}, {59, {630., 345.}}, {60, {570., 300.}}, {61, {630., 300.}}, {62, {420., 390.}}, {63, {630., 390.}}, {64, {450., 450.}}, {65, {450., 345.}}, {66, {390., 450.}}, {67, {420., 450.}}, {68, {390., 420.}}, {69, {420., 420.}}, {70, {390., 390.}}, {71, {420., 390.}}, {72, {420., 420.}}, {73, {540., 420.}}, {74, {420., 450.}}, {75, {450., 450.}}, {76, {450., 300.}}, {77, {510., 300.}}};
    
    preconfconfarestas[1] = {{{6, 7}, "bobcont", "C1"}, {{10, 11}, "fusivel"}, {{12, 13}, "fio", 0}, {{14, 15}, "botna", "B1"}, {{16, 17}, "fio", 0}, {{18, 19}, "contna", "C1"}, {{20, 21}, "fio", 0}, {{22, 23}, "fio", 0}, {{24, 25}, "botnf", "X1"}, {{26, 27}, "fio", 0}, {{28, 29}, "fio", 0}, {{30, 31}, "fio", 0}, {{32, 33}, "fio", 0}, {{34, 35}, "fio", 0}, {{36, 37}, "fusivel"}, {{38, 39}, "fio", 0}, {{44, 45}, "contna", "C1"}, {{46, 47}, "contna", "C1"}, {{48, 49}, "contna", "C1"}, {{50, 51}, "fio", 0}, {{52, 53}, "fio", 0}, {{54, 55}, "fio", 0}, {{56, 57}, "fio", 0}, {{58, 59}, "fio", 0}, {{60, 61}, "fio", 0}, {{62, 63}, "fio", 0}, {{64, 65}, "fio", 0}, {{66, 67}, "fusivel"}, {{68, 69}, "fusivel"}, {{70, 71}, "fusivel"}, {{72, 73}, "fio", 0}, {{74, 75}, "fio", 0}, {{76, 77}, "fio", 0}};
    
    preconfcargas[1] = {{40, "carga3f", "carga1", {41, 42, 43}}};
    
    comentario[1] = "Circuito extremamente simples";
    
    (*Circuito 2:*)
    preconfconfvertices[2] = {{1, {105., 600.}}, {2, {105., 405.}}, {3, {105., 330.}}, {4, {105., 300.}}, {5, {105., 270.}}, {6, {150., 465.}}, {7, {150., 405.}}, {8, {285., 465.}}, {9, {285., 405.}}, {10, {420., 465.}}, {11, {420., 405.}}, {12, {495., 465.}}, {13, {495., 405.}}, {14, {585., 465.}}, {15, {585., 405.}}, {16, {675., 465.}}, {17, {675., 405.}}, {18, {765., 465.}}, {19, {765., 405.}}, {20, {240., 150.}}, {21, {210., 165.}}, {22, {240., 165.}}, {23, {270., 165.}}, {24, {555., 150.}}, {25, {525., 165.}}, {26, {555., 165.}}, {27, {585., 165.}}, {28, {150., 510.}}, {29, {150., 495.}}, {30, {150., 555.}}, {31, {150., 540.}}, {32, {330., 240.}}, {33, {330., 180.}}, {34, {240., 240.}}, {35, {240., 180.}}, {36, {150., 240.}}, {37, {150., 180.}}, {38, {150., 585.}}, {39, {150., 570.}}, {40, {105., 600.}}, {41, {135., 600.}}, {42, {150., 600.}}, {43, {150., 585.}}, {44, {135., 600.}}, {45, {150., 600.}}, {46, {150., 540.}}, {47, {150., 525.}}, {48, {150., 570.}}, {49, {150., 555.}}, {50, {150., 525.}}, {51, {150., 510.}}, {52, {195., 510.}}, {53, {195., 495.}}, {54, {150., 525.}}, {55, {195., 525.}}, {56, {195., 525.}}, {57, {195., 510.}}, {58, {150., 495.}}, {59, {150., 480.}}, {60, {195., 495.}}, {61, {195., 480.}}, {62, {150., 480.}}, {63, {150., 465.}}, {64, {150., 480.}}, {65, {195., 480.}}, {66, {105., 405.}}, {67, {135., 405.}}, {68, {135., 405.}}, {69, {150., 405.}}, {70, {285., 510.}}, {71, {285., 495.}}, {72, {285., 600.}}, {73, {285., 510.}}, {74, {150., 405.}}, {75, {285., 405.}}, {76, {420., 600.}}, {77, {420., 510.}}, {78, {150., 600.}}, {79, {285., 600.}}, {80, {420., 510.}}, {81, {420., 495.}}, {82, {285., 405.}}, {83, {420., 405.}}, {84, {285., 495.}}, {85, {285., 465.}}, {86, {285., 600.}}, {87, {420., 600.}}, {88, {495., 600.}}, {89, {585., 600.}}, {90, {495., 510.}}, {91, {495., 495.}}, {92, {495., 540.}}, {93, {495., 525.}}, {94, {765., 495.}}, {95, {765., 465.}}, {96, {675., 495.}}, {97, {675., 465.}}, {98, {420., 495.}}, {99, {420., 465.}}, {100, {585., 600.}}, {101, {585., 510.}}, {102, {420., 600.}}, {103, {495., 600.}}, {104, {675., 510.}}, {105, {675., 495.}}, {106, {585., 510.}}, {107, {585., 495.}}, {108, {765., 510.}}, {109, {765., 495.}}, {110, {495., 495.}}, {111, {495., 465.}}, {112, {420., 405.}}, {113, {495., 405.}}, {114, {495., 405.}}, {115, {585., 405.}}, {116, {585., 600.}}, {117, {675., 600.}}, {118, {495., 600.}}, {119, {495., 540.}}, {120, {675., 405.}}, {121, {765., 405.}}, {122, {495., 525.}}, {123, {495., 510.}}, {124, {765., 600.}}, {125, {765., 510.}}, {126, {675., 600.}}, {127, {765., 600.}}, {128, {675., 600.}}, {129, {675., 510.}}, {130, {585., 405.}}, {131, {675., 405.}}, {132, {585., 495.}}, {133, {585., 465.}}, {134, {105., 270.}}, {135, {135., 270.}}, {136, {105., 300.}}, {137, {135., 300.}}, {138, {105., 330.}}, {139, {135., 330.}}, {140, {135., 300.}}, {141, {240., 300.}}, {142, {240., 300.}}, {143, {240., 240.}}, {144, {240., 180.}}, {145, {240., 165.}}, {146, {465., 330.}}, {147, {465., 240.}}, {148, {135., 270.}}, {149, {330., 270.}}, {150, {150., 330.}}, {151, {150., 240.}}, {152, {135., 330.}}, {153, {150., 330.}}, {154, {270., 165.}}, {155, {330., 165.}}, {156, {150., 165.}}, {157, {210., 165.}}, {158, {330., 180.}}, {159, {330., 165.}}, {160, {150., 180.}}, {161, {150., 165.}}, {162, {645., 240.}}, {163, {645., 225.}}, {164, {555., 240.}}, {165, {555., 225.}}, {166, {465., 240.}}, {167, {465., 225.}}, {168, {585., 165.}}, {169, {645., 165.}}, {170, {645., 225.}}, {171, {645., 165.}}, {172, {465., 225.}}, {173, {465., 165.}}, {174, {555., 225.}}, {175, {555., 165.}}, {176, {150., 330.}}, {177, {465., 330.}}, {178, {465., 165.}}, {179, {525., 165.}}, {180, {645., 270.}}, {181, {645., 240.}}, {182, {240., 300.}}, {183, {555., 300.}}, {184, {330., 270.}}, {185, {330., 240.}}, {186, {555., 300.}}, {187, {555., 240.}}, {188, {330., 270.}}, {189, {645., 270.}}};
    
    preconfconfarestas[2] = {{{6, 7}, "bobcont", "C1"}, {{8, 9}, "tempon", "D1", 5}, {{10, 11}, "bobcont", "C2"}, {{12, 13}, "lamp", "L1"}, {{14, 15}, "lamp", "L2"}, {{16, 17}, "lamp", "L3"}, {{18, 19}, "lamp", "L4"}, {{28, 29}, "botna", "B1"}, {{30, 31}, "botnf", "X1"}, {{32, 33}, "contnasensterm", "C1"}, {{34, 35}, "contnasensterm", "C1"}, {{36, 37}, "contnasensterm", "C1"}, {{38, 39}, "contnfterm", "C1"}, {{40, 41}, "fusivel"}, {{42, 43}, "fio", 0}, {{44, 45}, "fio", 0}, {{46, 47}, "fio", 0}, {{48, 49}, "fio", 0}, {{50, 51}, "fio", 0}, {{52, 53}, "contna", "C1"}, {{54, 55}, "fio", 0}, {{56, 57}, "fio", 0}, {{58, 59}, "fio", 0}, {{60, 61}, "fio", 0}, {{62, 63}, "fio", 0}, {{64, 65}, "fio", 0}, {{66, 67}, "fusivel"}, {{68, 69}, "fio", 0}, {{70, 71}, "contna", "C1"}, {{72, 73}, "fio", 0}, {{74, 75}, "fio", 0}, {{76, 77}, "fio", 0}, {{78, 79}, "fio", 0}, {{80, 81}, "contnatempon", "D1"}, {{82, 83}, "fio", 0}, {{84, 85}, "fio", 0}, {{86, 87}, "fio", 0}, {{88, 89}, "fio", 0}, {{90, 91}, "contnf", "C2"}, {{92, 93}, "contnf", "C1"}, {{94, 95}, "fio", 0}, {{96, 97}, "fio", 0}, {{98, 99}, "fio", 0}, {{100, 101}, "fio", 0}, {{102, 103}, "fio", 0}, {{104, 105}, "contna", "C2"}, {{106, 107}, "contna", "C1"}, {{108, 109}, "contnaterm", "C1"}, {{110, 111}, "fio", 0}, {{112, 113}, "fio", 0}, {{114, 115}, "fio", 0}, {{116, 117}, "fio", 0}, {{118, 119}, "fio", 0}, {{120, 121}, "fio", 0}, {{122, 123}, "fio", 0}, {{124, 125}, "fio", 0}, {{126, 127}, "fio", 0}, {{128, 129}, "fio", 0}, {{130, 131}, "fio", 0}, {{132, 133}, "fio", 0}, {{134, 135}, "fusivel"}, {{136, 137}, "fusivel"}, {{138, 139}, "fusivel"}, {{140, 141}, "fio", 0}, {{142, 143}, "fio", 0}, {{144, 145}, "fio", 0}, {{146, 147}, "fio", 0}, {{148, 149}, "fio", 0}, {{150, 151}, "fio", 0}, {{152, 153}, "fio", 0}, {{154, 155}, "fio", 0}, {{156, 157}, "fio", 0}, {{158, 159}, "fio", 0}, {{160, 161}, "fio", 0}, {{162, 163}, "contna", "C2"}, {{164, 165}, "contna", "C2"}, {{166, 167}, "contna", "C2"}, {{168, 169}, "fio", 0}, {{170, 171}, "fio", 0}, {{172, 173}, "fio", 0}, {{174, 175}, "fio", 0}, {{176, 177}, "fio", 0}, {{178, 179}, "fio", 0}, {{180, 181}, "fio", 0}, {{182, 183}, "fio", 0}, {{184, 185}, "fio", 0}, {{186, 187}, "fio", 0}, {{188, 189}, "fio", 0}};
    
    preconfcargas[2] = {{20, "carga3f", "carga1", {21, 22, 23}}, {24, "carga3f", "carga2", {25, 26, 27}}};
    
    comentario[2] = "Circuito com temporização... ";
    
    (*Circuito 3:*)
    preconfconfvertices[3] = {{1, {105., 600.}}, {2, {105., 390.}}, {3, {105., 315.}}, {4, {105., 285.}}, {5, {105., 255.}}, {6, {105., 390.}}, {7, {135., 390.}}, {8, {105., 600.}}, {9, {135., 600.}}, {10, {135., 555.}}, {11, {135., 540.}}, {12, {135., 585.}}, {13, {135., 570.}}, {14, {135., 600.}}, {15, {135., 585.}}, {16, {135., 570.}}, {17, {135., 555.}}, {18, {135., 450.}}, {19, {135., 390.}}, {20, {135., 540.}}, {21, {135., 525.}}, {22, {135., 525.}}, {23, {135., 510.}}, {24, {420., 555.}}, {25, {420., 540.}}, {26, {180., 510.}}, {27, {180., 495.}}, {28, {135., 510.}}, {29, {135., 495.}}, {30, {270., 510.}}, {31, {270., 495.}}, {32, {270., 480.}}, {33, {270., 465.}}, {34, {270., 495.}}, {35, {270., 480.}}, {36, {135., 525.}}, {37, {180., 525.}}, {38, {180., 525.}}, {39, {180., 510.}}, {40, {135., 495.}}, {41, {135., 480.}}, {42, {180., 495.}}, {43, {180., 480.}}, {44, {135., 480.}}, {45, {180., 480.}}, {46, {135., 480.}}, {47, {135., 450.}}, {48, {135., 600.}}, {49, {270., 600.}}, {50, {270., 600.}}, {51, {270., 585.}}, {52, {270., 585.}}, {53, {270., 570.}}, {54, {270., 450.}}, {55, {270., 390.}}, {56, {270., 555.}}, {57, {270., 540.}}, {58, {270., 570.}}, {59, {270., 555.}}, {60, {270., 540.}}, {61, {270., 525.}}, {62, {270., 465.}}, {63, {270., 450.}}, {64, {135., 390.}}, {65, {270., 390.}}, {66, {270., 525.}}, {67, {270., 510.}}, {68, {345., 525.}}, {69, {345., 510.}}, {70, {345., 510.}}, {71, {345., 495.}}, {72, {345., 495.}}, {73, {345., 450.}}, {74, {270., 390.}}, {75, {420., 390.}}, {76, {270., 525.}}, {77, {345., 525.}}, {78, {420., 510.}}, {79, {420., 495.}}, {80, {420., 600.}}, {81, {420., 555.}}, {82, {420., 450.}}, {83, {420., 390.}}, {84, {420., 495.}}, {85, {420., 450.}}, {86, {690., 585.}}, {87, {735., 585.}}, {88, {270., 450.}}, {89, {345., 450.}}, {90, {270., 600.}}, {91, {420., 600.}}, {92, {585., 510.}}, {93, {585., 495.}}, {94, {510., 555.}}, {95, {510., 540.}}, {96, {585., 555.}}, {97, {585., 540.}}, {98, {510., 510.}}, {99, {510., 495.}}, {100, {585., 585.}}, {101, {585., 555.}}, {102, {585., 540.}}, {103, {585., 510.}}, {104, {585., 495.}}, {105, {585., 480.}}, {106, {510., 495.}}, {107, {510., 480.}}, {108, {555., 480.}}, {109, {585., 480.}}, {110, {555., 480.}}, {111, {555., 450.}}, {112, {555., 450.}}, {113, {555., 390.}}, {114, {420., 390.}}, {115, {555., 390.}}, {116, {510., 480.}}, {117, {555., 480.}}, {118, {555., 585.}}, {119, {585., 585.}}, {120, {555., 585.}}, {121, {510., 585.}}, {122, {555., 600.}}, {123, {555., 585.}}, {124, {510., 540.}}, {125, {510., 510.}}, {126, {510., 585.}}, {127, {510., 555.}}, {128, {420., 600.}}, {129, {555., 600.}}, {130, {780., 555.}}, {131, {780., 540.}}, {132, {690., 555.}}, {133, {690., 540.}}, {134, {690., 585.}}, {135, {690., 555.}}, {136, {735., 600.}}, {137, {735., 585.}}, {138, {735., 585.}}, {139, {780., 585.}}, {140, {780., 540.}}, {141, {780., 525.}}, {142, {690., 540.}}, {143, {690., 525.}}, {144, {420., 540.}}, {145, {420., 510.}}, {146, {780., 585.}}, {147, {780., 555.}}, {148, {555., 600.}}, {149, {735., 600.}}, {150, {735., 525.}}, {151, {735., 450.}}, {152, {690., 525.}}, {153, {735., 525.}}, {154, {735., 525.}}, {155, {780., 525.}}, {156, {735., 450.}}, {157, {735., 390.}}, {158, {555., 390.}}, {159, {735., 390.}}, {160, {150., 210.}}, {161, {150., 150.}}, {162, {105., 285.}}, {163, {135., 285.}}, {164, {105., 315.}}, {165, {135., 315.}}, {166, {105., 255.}}, {167, {135., 255.}}, {168, {150., 315.}}, {169, {150., 210.}}, {170, {135., 315.}}, {171, {150., 315.}}, {172, {300., 210.}}, {173, {300., 150.}}, {174, {225., 210.}}, {175, {225., 150.}}, {176, {225., 120.}}, {177, {195., 135.}}, {178, {225., 135.}}, {179, {255., 135.}}, {180, {225., 150.}}, {181, {225., 135.}}, {182, {150., 150.}}, {183, {150., 135.}}, {184, {300., 150.}}, {185, {300., 135.}}, {186, {225., 285.}}, {187, {225., 210.}}, {188, {150., 135.}}, {189, {195., 135.}}, {190, {255., 135.}}, {191, {300., 135.}}, {192, {135., 285.}}, {193, {225., 285.}}, {194, {135., 255.}}, {195, {300., 255.}}, {196, {480., 285.}}, {197, {480., 210.}}, {198, {480., 120.}}, {199, {450., 135.}}, {200, {480., 135.}}, {201, {510., 135.}}, {202, {555., 210.}}, {203, {555., 150.}}, {204, {405., 210.}}, {205, {405., 150.}}, {206, {480., 210.}}, {207, {480., 150.}}, {208, {405., 135.}}, {209, {450., 135.}}, {210, {405., 150.}}, {211, {405., 135.}}, {212, {480., 150.}}, {213, {480., 135.}}, {214, {510., 135.}}, {215, {555., 135.}}, {216, {555., 150.}}, {217, {555., 135.}}, {218, {225., 285.}}, {219, {480., 285.}}, {220, {150., 315.}}, {221, {405., 315.}}, {222, {300., 255.}}, {223, {300., 210.}}, {224, {300., 255.}}, {225, {555., 255.}}, {226, {555., 255.}}, {227, {555., 210.}}, {228, {405., 315.}}, {229, {405., 210.}}};
    
    preconfconfarestas[3] = {{{6, 7}, "fusivel"}, {{8, 9}, "fusivel"}, {{10, 11}, "contnfterm", "C1"}, {{12, 13}, "botnf", "X1"}, {{14, 15}, "fio", 0}, {{16, 17}, "fio", 0}, {{18, 19}, "bobcont", "C1"}, {{20, 21}, "fio", 0}, {{22, 23}, "fio", 0}, {{24, 25}, "contna", "C1"}, {{26, 27}, "contna", "C1"}, {{28, 29}, "botna", "B1"}, {{30, 31}, "botna", "B2"}, {{32, 33}, "contna", "C1"}, {{34, 35}, "fio", 0}, {{36, 37}, "fio", 0}, {{38, 39}, "fio", 0}, {{40, 41}, "fio", 0}, {{42, 43}, "fio", 0}, {{44, 45}, "fio", 0}, {{46, 47}, "fio", 0}, {{48, 49}, "fio", 0}, {{50, 51}, "fio", 0}, {{52, 53}, "botnf", "X2"}, {{54, 55}, "bobcont", "C2"}, {{56, 57}, "contnfterm", "C2"}, {{58, 59}, "fio", 0}, {{60, 61}, "fio", 0}, {{62, 63}, "fio", 0}, {{64, 65}, "fio", 0}, {{66, 67}, "fio", 0}, {{68, 69}, "fio", 0}, {{70, 71}, "contna", "C2"}, {{72, 73}, "fio", 0}, {{74, 75}, "fio", 0}, {{76, 77}, "fio", 0}, {{78, 79}, "contna", "C2"}, {{80, 81}, "fio", 0}, {{82, 83}, "lamp", "L1"}, {{84, 85}, "fio", 0}, {{86, 87}, "fio", 0}, {{88, 89}, "fio", 0}, {{90, 91}, "fio", 0}, {{92, 93}, "contna", "C2"}, {{94, 95}, "contna", "C1"}, {{96, 97}, "contnf", "C1"}, {{98, 99}, "contnf", "C2"}, {{100, 101}, "fio", 0}, {{102, 103}, "fio", 0}, {{104, 105}, "fio", 0}, {{106, 107}, "fio", 0}, {{108, 109}, "fio", 0}, {{110, 111}, "fio", 0}, {{112, 113}, "lamp", "L2"}, {{114, 115}, "fio", 0}, {{116, 117}, "fio", 0}, {{118, 119}, "fio", 0}, {{120, 121}, "fio", 0}, {{122, 123}, "fio", 0}, {{124, 125}, "fio", 0}, {{126, 127}, "fio", 0}, {{128, 129}, "fio", 0}, {{130, 131}, "contnaterm", "C2"}, {{132, 133}, "contnaterm", "C1"}, {{134, 135}, "fio", 0}, {{136, 137}, "fio", 0}, {{138, 139}, "fio", 0}, {{140, 141}, "fio", 0}, {{142, 143}, "fio", 0}, {{144, 145}, "fio", 0}, {{146, 147}, "fio", 0}, {{148, 149}, "fio", 0}, {{150, 151}, "fio", 0}, {{152, 153}, "fio", 0}, {{154, 155}, "fio", 0}, {{156, 157}, "lamp", "L3"}, {{158, 159}, "fio", 0}, {{160, 161}, "contnasensterm", "C1"}, {{162, 163}, "fusivel"}, {{164, 165}, "fusivel"}, {{166, 167}, "fusivel"}, {{168, 169}, "fio", 0}, {{170, 171}, "fio", 0}, {{172, 173}, "contnasensterm", "C1"}, {{174, 175}, "contnasensterm", "C1"}, {{180, 181}, "fio", 0}, {{182, 183}, "fio", 0}, {{184, 185}, "fio", 0}, {{186, 187}, "fio", 0}, {{188, 189}, "fio", 0}, {{190, 191}, "fio", 0}, {{192, 193}, "fio", 0}, {{194, 195}, "fio", 0}, {{196, 197}, "fio", 0}, {{202, 203}, "contnasensterm", "C2"}, {{204, 205}, "contnasensterm", "C2"}, {{206, 207}, "contnasensterm", "C2"}, {{208, 209}, "fio", 0}, {{210, 211}, "fio", 0}, {{212, 213}, "fio", 0}, {{214, 215}, "fio", 0}, {{216, 217}, "fio", 0}, {{218, 219}, "fio", 0}, {{220, 221}, "fio", 0}, {{222, 223}, "fio", 0}, {{224, 225}, "fio", 0}, {{226, 227}, "fio", 0}, {{228, 229}, "fio", 0}};
    
    preconfcargas[3] = {{176, "carga3f", "carga1", {177, 178, 179}}, {198, "carga3f", "carga2", {199, 200, 201}}};
    
    comentario[3] = "Duas cargas com pré-condição";
    
    (*Circuito 4:*)
    preconfconfvertices[4] = {{1, {120., 645.}}, {2, {120., 345.}}, {3, {120., 300.}}, {4, {120., 270.}}, {5, {120., 240.}}, {6, {165., 405.}}, {7, {165., 345.}}, {8, {120., 345.}}, {9, {150., 345.}}, {10, {165., 450.}}, {11, {165., 435.}}, {12, {255., 450.}}, {13, {255., 435.}}, {14, {345., 405.}}, {15, {345., 345.}}, {16, {345., 450.}}, {17, {345., 435.}}, {18, {525., 555.}}, {19, {525., 540.}}, {20, {420., 495.}}, {21, {420., 480.}}, {22, {525., 405.}}, {23, {525., 345.}}, {24, {165., 495.}}, {25, {165., 480.}}, {26, {480., 225.}}, {27, {480., 165.}}, {32, {165., 630.}}, {33, {165., 615.}}, {34, {120., 645.}}, {35, {150., 645.}}, {36, {150., 645.}}, {37, {165., 645.}}, {38, {165., 645.}}, {39, {165., 630.}}, {40, {165., 615.}}, {41, {165., 600.}}, {42, {165., 585.}}, {43, {165., 570.}}, {44, {165., 555.}}, {45, {165., 525.}}, {46, {165., 525.}}, {47, {345., 525.}}, {48, {420., 480.}}, {49, {420., 405.}}, {50, {255., 435.}}, {51, {255., 405.}}, {52, {165., 465.}}, {53, {255., 465.}}, {54, {165., 405.}}, {55, {255., 405.}}, {56, {150., 345.}}, {57, {165., 345.}}, {58, {165., 465.}}, {59, {165., 450.}}, {60, {165., 480.}}, {61, {165., 465.}}, {62, {165., 435.}}, {63, {165., 405.}}, {64, {525., 645.}}, {65, {525., 555.}}, {66, {165., 525.}}, {67, {165., 495.}}, {68, {255., 465.}}, {69, {255., 450.}}, {70, {345., 405.}}, {71, {420., 405.}}, {72, {165., 345.}}, {73, {345., 345.}}, {74, {345., 480.}}, {75, {345., 450.}}, {76, {345., 525.}}, {77, {345., 495.}}, {78, {345., 525.}}, {79, {420., 525.}}, {80, {345., 435.}}, {81, {345., 405.}}, {82, {525., 540.}}, {83, {525., 495.}}, {84, {165., 645.}}, {85, {525., 645.}}, {86, {345., 495.}}, {87, {345., 480.}}, {88, {525., 495.}}, {89, {525., 480.}}, {90, {525., 480.}}, {91, {525., 405.}}, {92, {420., 525.}}, {93, {420., 495.}}, {94, {345., 345.}}, {95, {525., 345.}}, {96, {120., 300.}}, {97, {150., 300.}}, {98, {120., 270.}}, {99, {150., 270.}}, {100, {120., 240.}}, {101, {150., 240.}}, {102, {150., 300.}}, {103, {210., 300.}}, {104, {285., 135.}}, {105, {255., 150.}}, {106, {285., 150.}}, {107, {315., 150.}}, {108, {210., 225.}}, {109, {210., 165.}}, {110, {285., 225.}}, {111, {285., 165.}}, {112, {360., 225.}}, {113, {360., 165.}}, {114, {360., 240.}}, {115, {360., 225.}}, {116, {150., 240.}}, {117, {360., 240.}}, {118, {315., 165.}}, {119, {315., 150.}}, {120, {255., 165.}}, {121, {255., 150.}}, {122, {285., 165.}}, {123, {285., 150.}}, {124, {210., 165.}}, {125, {255., 165.}}, {126, {360., 165.}}, {127, {315., 165.}}, {128, {150., 270.}}, {129, {285., 270.}}, {130, {285., 270.}}, {131, {285., 225.}}, {132, {210., 300.}}, {133, {210., 225.}}, {134, {555., 135.}}, {135, {525., 150.}}, {136, {555., 150.}}, {137, {585., 150.}}, {138, {555., 225.}}, {139, {555., 165.}}, {140, {630., 225.}}, {141, {630., 165.}}, {142, {630., 240.}}, {143, {630., 225.}}, {144, {480., 300.}}, {145, {480., 225.}}, {146, {525., 165.}}, {147, {525., 150.}}, {148, {630., 165.}}, {149, {585., 165.}}, {150, {480., 165.}}, {151, {525., 165.}}, {152, {360., 240.}}, {153, {630., 240.}}, {154, {285., 270.}}, {155, {555., 270.}}, {156, {210., 300.}}, {157, {480., 300.}}, {158, {585., 165.}}, {159, {585., 150.}}, {160, {555., 165.}}, {161, {555., 150.}}, {162, {555., 270.}}, {163, {555., 225.}}, {164, {165., 600.}}, {165, {165., 585.}}, {166, {165., 570.}}, {167, {165., 555.}}};
    
    preconfconfarestas[4] = {{{6, 7}, "bobcont", "C1"}, {{8, 9}, "fusivel"}, {{10, 11}, "botna", "B1"}, {{12, 13}, "contna", "C1"}, {{14, 15}, "bobcont", "C2"}, {{16, 17}, "botna", "B2"}, {{18, 19}, "contna", "C1"}, {{20, 21}, "contna", "C2"}, {{22, 23}, "tempon", "D1", 10}, {{24, 25}, "contnftempon", "D1"}, {{26, 27}, "contnasensterm", "C2"}, {{32, 33}, "botnf", "X1"}, {{34, 35}, "fusivel"}, {{36, 37}, "fio", 0}, {{38, 39}, "fio", 0}, {{40, 41}, "fio", 0}, {{42, 43}, "fio", 0}, {{44, 45}, "fio", 0}, {{46, 47}, "fio", 0}, {{48, 49}, "fio", 0}, {{50, 51}, "fio", 0}, {{52, 53}, "fio", 0}, {{54, 55}, "fio", 0}, {{56, 57}, "fio", 0}, {{58, 59}, "fio", 0}, {{60, 61}, "fio", 0}, {{62, 63}, "fio", 0}, {{64, 65}, "fio", 0}, {{66, 67}, "fio", 0}, {{68, 69}, "fio", 0}, {{70, 71}, "fio", 0}, {{72, 73}, "fio", 0}, {{74, 75}, "fio", 0}, {{76, 77}, "fio", 0}, {{78, 79}, "fio", 0}, {{80, 81}, "fio", 0}, {{82, 83}, "fio", 0}, {{84, 85}, "fio", 0}, {{86, 87}, "contna", "C1"}, {{88, 89}, "contnf", "C2"}, {{90, 91}, "fio", 0}, {{92, 93}, "fio", 0}, {{94, 95}, "fio", 0}, {{96, 97}, "fusivel"}, {{98, 99}, "fusivel"}, {{100, 101}, "fusivel"}, {{102, 103}, "fio", 0}, {{108, 109}, "contnasensterm", "C1"}, {{110, 111}, "contnasensterm", "C1"}, {{112, 113}, "contnasensterm", "C1"}, {{114, 115}, "fio", 0}, {{116, 117}, "fio", 0}, {{118, 119}, "fio", 0}, {{120, 121}, "fio", 0}, {{122, 123}, "fio", 0}, {{124, 125}, "fio", 0}, {{126, 127}, "fio", 0}, {{128, 129}, "fio", 0}, {{130, 131}, "fio", 0}, {{132, 133}, "fio", 0}, {{138, 139}, "contnasensterm", "C2"}, {{140, 141}, "contnasensterm", "C2"}, {{142, 143}, "fio", 0}, {{144, 145}, "fio", 0}, {{146, 147}, "fio", 0}, {{148, 149}, "fio", 0}, {{150, 151}, "fio", 0}, {{152, 153}, "fio", 0}, {{154, 155}, "fio", 0}, {{156, 157}, "fio", 0}, {{158, 159}, "fio", 0}, {{160, 161}, "fio", 0}, {{162, 163}, "fio", 0}, {{164, 165}, "contnfterm", "C1"}, {{166, 167}, "contnfterm", "C2"}};
    
    preconfcargas[4] = {{104, "carga3f", "carga1", {105, 106, 107}}, {134, "carga3f", "carga2", {135, 136, 137}}};
    
    comentario[4] = "Outro esquema de temporização";
    
    (*Circuito 5:*)preconfconfvertices[5] = {{1, {105., 645.}}, {2, {105., 360.}}, {3, {225., 315.}}, {4, {225., 285.}}, {5, {225., 255.}}, {6, {225., 420.}}, {7, {225., 360.}}, {8, {420., 420.}}, {9, {420., 360.}}, {10, {210., 630.}}, {11, {210., 615.}}, {12, {135., 630.}}, {13, {135., 615.}}, {14, {135., 420.}}, {15, {135., 360.}}, {16, {345., 420.}}, {17, {345., 360.}}, {18, {210., 600.}}, {19, {210., 585.}}, {20, {135., 480.}}, {21, {135., 465.}}, {22, {135., 555.}}, {23, {135., 540.}}, {24, {345., 240.}}, {25, {345., 180.}}, {26, {270., 240.}}, {27, {270., 180.}}, {28, {135., 525.}}, {29, {135., 510.}}, {30, {135., 645.}}, {31, {135., 630.}}, {32, {105., 360.}}, {33, {135., 360.}}, {34, {105., 645.}}, {35, {135., 645.}}, {36, {210., 615.}}, {37, {210., 600.}}, {38, {210., 585.}}, {39, {210., 570.}}, {40, {210., 570.}}, {41, {135., 570.}}, {42, {135., 615.}}, {43, {135., 570.}}, {44, {135., 570.}}, {45, {135., 555.}}, {46, {135., 540.}}, {47, {135., 525.}}, {48, {135., 510.}}, {49, {135., 495.}}, {50, {210., 480.}}, {51, {210., 465.}}, {52, {135., 495.}}, {53, {210., 495.}}, {54, {210., 495.}}, {55, {210., 480.}}, {56, {135., 495.}}, {57, {135., 480.}}, {58, {135., 450.}}, {59, {210., 450.}}, {60, {210., 465.}}, {61, {210., 450.}}, {62, {135., 465.}}, {63, {135., 450.}}, {64, {135., 450.}}, {65, {135., 435.}}, {66, {135., 435.}}, {67, {225., 435.}}, {68, {225., 435.}}, {69, {225., 420.}}, {70, {135., 435.}}, {71, {135., 420.}}, {72, {135., 360.}}, {73, {225., 360.}}, {74, {345., 465.}}, {75, {345., 450.}}, {76, {225., 360.}}, {77, {345., 360.}}, {78, {345., 480.}}, {79, {345., 465.}}, {80, {420., 480.}}, {81, {420., 465.}}, {82, {345., 450.}}, {83, {420., 450.}}, {84, {345., 450.}}, {85, {345., 435.}}, {86, {420., 465.}}, {87, {420., 450.}}, {88, {210., 645.}}, {89, {210., 630.}}, {90, {135., 645.}}, {91, {210., 645.}}, {92, {345., 435.}}, {93, {345., 420.}}, {94, {345., 420.}}, {95, {420., 420.}}, {96, {345., 360.}}, {97, {420., 360.}}, {98, {345., 135.}}, {99, {315., 150.}}, {100, {345., 150.}}, {101, {375., 150.}}, {102, {270., 165.}}, {103, {315., 165.}}, {104, {315., 165.}}, {105, {315., 150.}}, {106, {270., 315.}}, {107, {270., 240.}}, {108, {270., 180.}}, {109, {270., 165.}}, {110, {225., 255.}}, {111, {255., 255.}}, {112, {225., 285.}}, {113, {255., 285.}}, {114, {225., 315.}}, {115, {255., 315.}}, {116, {255., 315.}}, {117, {270., 315.}}, {118, {420., 180.}}, {119, {420., 165.}}, {120, {345., 180.}}, {121, {345., 150.}}, {122, {420., 255.}}, {123, {420., 240.}}, {124, {255., 255.}}, {125, {420., 255.}}, {126, {345., 285.}}, {127, {345., 240.}}, {128, {255., 285.}}, {129, {345., 285.}}, {130, {420., 240.}}, {131, {420., 180.}}, {132, {510., 165.}}, {133, {555., 165.}}, {134, {510., 180.}}, {135, {510., 165.}}, {136, {420., 165.}}, {137, {375., 165.}}, {138, {375., 165.}}, {139, {375., 150.}}, {140, {585., 135.}}, {141, {555., 150.}}, {142, {585., 150.}}, {143, {615., 150.}}, {144, {510., 240.}}, {145, {510., 180.}}, {146, {585., 240.}}, {147, {585., 180.}}, {148, {660., 240.}}, {149, {660., 180.}}, {150, {555., 165.}}, {151, {555., 150.}}, {152, {585., 180.}}, {153, {585., 150.}}, {154, {660., 180.}}, {155, {660., 165.}}, {156, {660., 165.}}, {157, {615., 165.}}, {158, {615., 165.}}, {159, {615., 150.}}, {160, {345., 285.}}, {161, {585., 285.}}, {162, {510., 315.}}, {163, {510., 240.}}, {164, {270., 315.}}, {165, {510., 315.}}, {166, {585., 285.}}, {167, {585., 240.}}, {168, {420., 255.}}, {169, {660., 255.}}, {170, {660., 255.}}, {171, {660., 240.}}, {172, {420., 630.}}, {173, {420., 615.}}, {174, {345., 630.}}, {175, {345., 615.}}, {176, {345., 555.}}, {177, {345., 540.}}, {178, {420., 615.}}, {179, {420., 570.}}, {180, {345., 615.}}, {181, {345., 570.}}, {182, {345., 570.}}, {183, {345., 555.}}, {184, {345., 570.}}, {185, {420., 570.}}, {186, {345., 540.}}, {187, {345., 525.}}, {188, {345., 525.}}, {189, {345., 510.}}, {190, {420., 495.}}, {191, {420., 480.}}, {192, {345., 495.}}, {193, {420., 495.}}, {194, {345., 510.}}, {195, {345., 495.}}, {196, {345., 495.}}, {197, {345., 480.}}, {198, {210., 645.}}, {199, {345., 645.}}, {200, {345., 645.}}, {201, {420., 645.}}, {202, {345., 645.}}, {203, {345., 630.}}, {204, {420., 645.}}, {205, {420., 630.}}, {206, {525., 420.}}, {207, {525., 360.}}, {208, {600., 420.}}, {209, {600., 360.}}, {210, {690., 420.}}, {211, {690., 360.}}, {212, {780., 420.}}, {213, {780., 360.}}, {214, {600., 570.}}, {215, {600., 555.}}, {216, {525., 570.}}, {217, {525., 555.}}, {218, {525., 555.}}, {219, {525., 420.}}, {220, {690., 570.}}, {221, {690., 555.}}, {222, {780., 570.}}, {223, {780., 555.}}, {224, {420., 360.}}, {225, {525., 360.}}, {226, {690., 360.}}, {227, {780., 360.}}, {228, {600., 360.}}, {229, {690., 360.}}, {230, {525., 360.}}, {231, {600., 360.}}, {232, {525., 645.}}, {233, {525., 570.}}, {234, {781.364, 554.091}}, {235, {781.364, 419.091}}, {236, {690., 555.}}, {237, {690., 420.}}, {238, {600., 555.}}, {239, {600., 420.}}, {240, {600., 645.}}, {241, {600., 570.}}, {242, {420., 645.}}, {243, {525., 645.}}, {244, {600., 645.}}, {245, {690., 645.}}, {246, {525., 645.}}, {247, {600., 645.}}, {248, {780., 645.}}, {249, {780., 570.}}, {250, {690., 645.}}, {251, {690., 570.}}, {252, {690., 645.}}, {253, {780., 645.}}};
    
    preconfconfarestas[5] = {{{6, 7}, "tempon", "D1", 10}, {{8, 9}, "tempon", "D2", 5}, {{10, 11}, "contnftempon", "D2"}, {{12, 13}, "contnftempon", "D1"}, {{14, 15}, "bobcont", "C1"}, {{16, 17}, "bobcont", "C2"}, {{18, 19}, "contna", "C2"}, {{20, 21}, "botna", "B1"}, {{22, 23}, "botnf", "X1"}, {{24, 25}, "contnasensterm", "C1"}, {{26, 27}, "contnasensterm", "C1"}, {{28, 29}, "contnfterm", "C1"}, {{30, 31}, "fio", 0}, {{32, 33}, "fusivel"}, {{34, 35}, "fusivel"}, {{36, 37}, "fio", 0}, {{38, 39}, "fio", 0}, {{40, 41}, "fio", 0}, {{42, 43}, "fio", 0}, {{44, 45}, "fio", 0}, {{46, 47}, "fio", 0}, {{48, 49}, "fio", 0}, {{50, 51}, "contna", "C1"}, {{52, 53}, "fio", 0}, {{54, 55}, "fio", 0}, {{56, 57}, "fio", 0}, {{58, 59}, "fio", 0}, {{60, 61}, "fio", 0}, {{62, 63}, "fio", 0}, {{64, 65}, "fio", 0}, {{66, 67}, "fio", 0}, {{68, 69}, "fio", 0}, {{70, 71}, "fio", 0}, {{72, 73}, "fio", 0}, {{74, 75}, "fio", 0}, {{76, 77}, "fio", 0}, {{78, 79}, "botna", "B2"}, {{80, 81}, "contna", "C2"}, {{82, 83}, "fio", 0}, {{84, 85}, "fio", 0}, {{86, 87}, "fio", 0}, {{88, 89}, "fio", 0}, {{90, 91}, "fio", 0}, {{92, 93}, "fio", 0}, {{94, 95}, "fio", 0}, {{96, 97}, "fio", 0}, {{102, 103}, "fio", 0}, {{104, 105}, "fio", 0}, {{106, 107}, "fio", 0}, {{108, 109}, "fio", 0}, {{110, 111}, "fusivel"}, {{112, 113}, "fusivel"}, {{114, 115}, "fusivel"}, {{116, 117}, "fio", 0}, {{118, 119}, "fio", 0}, {{120, 121}, "fio", 0}, {{122, 123}, "fio", 0}, {{124, 125}, "fio", 0}, {{126, 127}, "fio", 0}, {{128, 129}, "fio", 0}, {{130, 131}, "contnasensterm", "C1"}, {{132, 133}, "fio", 0}, {{134, 135}, "fio", 0}, {{136, 137}, "fio", 0}, {{138, 139}, "fio", 0}, {{144, 145}, "contnasensterm", "C2"}, {{146, 147}, "contnasensterm", "C2"}, {{148, 149}, "contnasensterm", "C2"}, {{150, 151}, "fio", 0}, {{152, 153}, "fio", 0}, {{154, 155}, "fio", 0}, {{156, 157}, "fio", 0}, {{158, 159}, "fio", 0}, {{160, 161}, "fio", 0}, {{162, 163}, "fio", 0}, {{164, 165}, "fio", 0}, {{166, 167}, "fio", 0}, {{168, 169}, "fio", 0}, {{170, 171}, "fio", 0}, {{172, 173}, "contna", "C1"}, {{174, 175}, "contnatempon", "D2"}, {{176, 177}, "botnf", "X2"}, {{178, 179}, "fio", 0}, {{180, 181}, "fio", 0}, {{182, 183}, "fio", 0}, {{184, 185}, "fio", 0}, {{186, 187}, "fio", 0}, {{188, 189}, "contnfterm", "C2"}, {{190, 191}, "fio", 0}, {{192, 193}, "fio", 0}, {{194, 195}, "fio", 0}, {{196, 197}, "fio", 0}, {{198, 199}, "fio", 0}, {{200, 201}, "fio", 0}, {{202, 203}, "fio", 0}, {{204, 205}, "fio", 0}, {{206, 207}, "lamp", "L1"}, {{208, 209}, "lamp", "L2"}, {{210, 211}, "lamp", "L3"}, {{212, 213}, "lamp", "L4"}, {{214, 215}, "contna", "C2"}, {{216, 217}, "contna", "C1"}, {{218, 219}, "fio", 0}, {{220, 221}, "contnaterm", "C1"}, {{222, 223}, "contnaterm", "C2"}, {{224, 225}, "fio", 0}, {{226, 227}, "fio", 0}, {{228, 229}, "fio", 0}, {{230, 231}, "fio", 0}, {{232, 233}, "fio", 0}, {{234, 235}, "fio", 0}, {{236, 237}, "fio", 0}, {{238, 239}, "fio", 0}, {{240, 241}, "fio", 0}, {{242, 243}, "fio", 0}, {{244, 245}, "fio", 0}, {{246, 247}, "fio", 0}, {{248, 249}, "fio", 0}, {{250, 251}, "fio", 0}, {{252, 253}, "fio", 0}};
    
    preconfcargas[5] = {{98, "carga3f", "carga1", {99, 100, 101}}, {140, "carga3f", "carga2", {141, 142, 143}}};
    
    comentario[5] = "Temporização e economia de energia";
    
    (*Circuito 6:*)
    preconfconfvertices[6] = {{1, {105., 640.}}, {2, {105., 350.}}, {3, {550., 450.}}, {4, {550., 410.}}, {5, {550., 370.}}};
    
    preconfconfarestas[6] = {};
    
    preconfcargas[6] = {};
    
    comentario[6] = "Novo";
    
    (* Fim da lista de circuitos pré-configurados, limite de 20 *)
    
    listpreconf = {};
    Do[Which[Length[preconfconfvertices[c]] > 1, (
       AppendTo[listpreconf, c -> (ToString@c <> ": " <> If[StringQ[comentario[c]], comentario[c], " "])];
       )], {c, 1, 20}];
    (*escolhapreconf=listpreconf[[1,1]];*)
    escolhapreconf = listpreconf[[1, 1]];
    
    saida = {};
    
    mododebug = True;
    objeto = Null;
    tamanho = {950, 750};
    passox = 15.; passoy = 15.;
    (*apagarvertices={};
    apagararestas={};
    novosvertices={};
    novasarestas={};
    vertlixeira={};
    apagarcargas={};*)
    
    (* Região que representa a lixeira *)
    lixeira = Rectangle[{52 passox, passoy}, {58 passox, 6 passoy}];
    (* Botão que efetiva a exclusão dos elementos*)
    botlixeira = Button[Pane["Apaga", {50, 2 passoy}, Alignment -> Center], (
       apagarvertices = {};
       apagararestas = {};
       novosvertices = {};
       novasarestas = {};
       vertlixeira = {};
       apagarcargas = {};
       temp1 = {};
       temp2 = {};
       temp3 = {};
       
       (* Verifica quais vertices se encontra internos à região da lixeira *)
       vertlixeira = Select[confconfvertices[[;; , 2]], (Between[#[[1]], {lixeira[[1, 1]], lixeira[[2, 1]]}] && Between[#[[2]], {lixeira[[1, 2]], lixeira[[2, 2]]}]) &];
       
       (* Os vertices não devem ser apagados imediatamente; primeiro, os índices dos vertices a serem apagados são armazenados em uma lista, ... *)
       (*são os índices dentro do vetor, não necessariamente o número do vértice do grafo, pois pode haver descontinuidade na numeração*)
       apagarvertices = If[Length@vertlixeira > 0,
         (temp1 = {};
          For[c = 1, c <= Length@vertlixeira, c++,
           (aux1 = Position[confconfvertices[[;; , 2]], vertlixeira[[c]]];
            temp1 = If[Length@aux1 > 0, (Append[temp1, aux1[[1]] ]), temp1])];
          temp1
          ), {}];
       
       (* ... e são buscadas as arestas conectadas a esses vértices. As arestas devem ser apagadas primeiro. *)
       apagararestas = If [Length[apagarvertices] > 0,
         (
          temp2 = {};
          For[c = 1, c <= Length@apagarvertices, c++, (
            aux2 = Position[confconfarestas[[;; , 1]], confconfvertices[[ apagarvertices[[c, 1]], 1 ]]];
            temp2 = If[Length@aux2 > 0, Append[temp2, aux2[[;; , 1]]], temp2])];
          DeleteDuplicates@temp2
          ), {}];
       
       
       (*Quando se apagam bobinas de contatores e temporizadores, devem-se buscar as arestas dependentes (contatos NA e NF)*)
       novasarestas = (
         If[Length@apagararestas > 0, (
           temp3 = {};
           For[c = 1, c <= Length@apagararestas, c++,
            (temp3 = If[
               (StringMatchQ[confconfarestas[[ apagararestas[[c, 1]], 2]], "bob*"] || StringMatchQ[confconfarestas[[ apagararestas[[c, 1]], 2]], "tempo*"])
               , (Join[temp3, Position[confconfarestas[[ ;; ]], confconfarestas[[ apagararestas[[c, 1]], 3]]][[;; , {1}]]])
               , temp3])
            ];
           ),
          {}];
         temp3
         );
       
       
       apagararestas = DeleteDuplicates@Join[apagararestas, novasarestas];
       
       (* busca os vertice correspondentes às novas arestas *)
       aux4 = Flatten@confconfarestas[[Flatten@apagararestas]][[;; , 1]] ;
       novosvertices = (
         If[Length@aux4 > 0, (
           temp4 = {};
           For[c = 1, c <= Length@aux4, c++,
            (
             Join[temp4, Position[confconfvertices, aux4[[c]]]];
             )
            ];
           ),
          {}];
         temp4
         );
       
       
       apagarvertices = DeleteDuplicates@Join[apagarvertices, novosvertices];
       
       (* Verifica-se se os vértices são os de Fases. Esses não podem ser apagados *)
       If[Length@apagarvertices > 0, (
         aux = {};
         For[c = 1, c <= Length@apagarvertices, c++,
          (If[MemberQ[{verticeF1, verticeF2, verticeP1, verticeP2, verticeP3}, apagarvertices[[c, 1]]], AppendTo[aux, c], {}];
           )];
         apagarvertices = Delete[apagarvertices, aux];
         ), {}];
       
       (* Verifica se há cargas a apagar *)
       If[Length@apagarvertices > 0, (
         apagarcargas = {};
         If[Length@confcargas > 0, (
           For[c = 1, c <= Length@confcargas, c++, (
              If[MemberQ[apagarvertices, {confcargas[[c, 1]]}], AppendTo[apagarcargas, {c}], {}])];
           
           ), {}];
         )];
       
       (* apagar os vertices correspondentes às arestas dependentes*)
       confcargas = Delete[confcargas, apagarcargas];
       confconfarestas = Delete[confconfarestas, apagararestas];
       confconfvertices = Delete[confconfvertices, apagarvertices];
       )];
    run = False;
    
    
    verticeF1 = 1;
    verticeF2 = 2;
    verticeP1 = 3;
    verticeP2 = 4;
    verticeP3 = 5;
    
    barra = 80.;
    teste = 0.;
    
    (* Escolha inicial do circuito. Será atualizada pelo popup *)
    confconfvertices = preconfconfvertices[escolhapreconf];
    confconfarestas = preconfconfarestas[escolhapreconf];
    confcargas = preconfcargas[escolhapreconf];
    
    ptosgrid = Table[{x, y}, {y, Max[barra, passoy], tamanho[[2]] - passoy, passoy}, {x, passox, tamanho[[1]] - passox, passox}];
    z = Flatten[ptosgrid, 1];
    (*fig1pos={0,0};*)(*fig1=Graphics[{Yellow,Opacity[0.7],Rectangle[{0,0},{2passox,2passoy}]}];fig1tam={2passox,2passoy};*)
    (*bobcontmodelo={Yellow,Opacity[0.7],Rectangle[{-passox,-passoy},{passox,passoy}]};*)
    bobcontmodelo = {EdgeForm[Black], Opacity[1], Line[{{0, -passoy}, {0, -0.5 passoy}}], Line[{{0, 0.5 passoy}, {0, passoy}}], FaceForm[Transparent], Rectangle[{-passox, -0.5 passoy}, {passox, 0.5 passoy}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, passoy}}], EdgeForm[Transparent], Rectangle[{-passox, -passoy}, {passox, passoy}]};
    temponmodelo = {EdgeForm[Black], Opacity[1], Line[{{0, -passoy}, {0, -0.5 passoy}}], Line[{{0, 0.5 passoy}, {0, passoy}}], FaceForm[Transparent], Rectangle[{-passox, -0.5 passoy}, {passox, 0.5 passoy}]
      , Line[{{-passox, -0.5 passoy}, {-0.5 passox, 0.5 passoy}, {-0.5 passox, -0.5 passoy}, {-passox, 0.5 passoy}}]
      , AbsolutePointSize[4], Point[{{0, -passoy}, {0, passoy}}], EdgeForm[Transparent], Rectangle[{-passox, -passoy}, {passox, passoy}]};
    contnamodelo = {Opacity[1], Line[{{0, -passoy}, {-0.5 passox, 0 passoy}}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, 0}}]
      (*,FaceForm[Transparent],EdgeForm[Transparent],Rectangle[{-passox,-passoy},{passox,passoy}]*)
      };
    contnfmodelo = {Opacity[1], Line[{{0, -passoy}, {0.5 passox, 0 passoy}, {0 passox, 0 passoy}}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, 0}}]
      (*,FaceForm[Transparent],EdgeForm[Transparent],Rectangle[{-passox,-passoy},{passox,passoy}]*)
      };
    botnamodelo = {Opacity[1], Line[{{0, -passoy}, {-0.5 passox, 0 passoy}}], Line[{{-0.25 passox, -0.5 passoy}, {-0.8 passox, -0.5 passoy}}], Line[{{-0.8 passox, -0.2 passoy}, {-0.8 passox, -0.8 passoy}}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, 0}}]
      (*,FaceForm[Transparent],EdgeForm[Transparent],Rectangle[{-passox,-passoy},{passox,passoy}]*)
      };
    botnfmodelo = {Opacity[1], Line[{{0, -passoy}, {0.5 passox, 0 passoy}, {0 passox, 0 passoy}}], Line[{{0.25 passox, -0.5 passoy}, {-0.8 passox, -0.5 passoy}}], Line[{{-0.8 passox, -0.2 passoy}, {-0.8 passox, -0.8 passoy}}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, 0}}]
      (*,FaceForm[Transparent],EdgeForm[Transparent],Rectangle[{-passox,-passoy},{passox,passoy}]*)
      };
    lampmodelo = {Opacity[1], Circle[{0, 0}, 0.5 passox], Line[{{0., -passoy}, {0., -0.5 passoy}}], Line[{{0., 0.5 passoy}, {0., passoy}}], Line[0.25 Sqrt[2.] passox {{-1, -1}, {1, 1}}], Line[0.25 Sqrt[2.] passox {{1, -1}, {-1, 1}}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, passoy}}]};
    fiomodelo = {Opacity[1], Line[{{0., -passoy}, {0., passoy}}], Disk[{0., passoy}, 2], Lighter[Black, 0.5], Disk[{0., -passoy}, 2]};
    fusivelmodelo = {Opacity[1], Line[{{-passox, 0.}, {passox, 0.}}], EdgeForm[Black], FaceForm[Transparent], Rectangle[{-0.5 passox, -0.25 passoy}, {0.5 passox, 0.25 passoy}], AbsolutePointSize[4], Point[{{-passox, 0.}, {passox, 0.}}]};
    contnasenstermmodelo = {Opacity[1], Line[{{0 passox, -passoy}, {-0.5 passox, 0 passoy}}]
      , Line[{{0 passox, 0 passoy}, {0. passox, 1. passoy}, {0.5 passox, 1. passoy}, {0.5 passox, 2. passoy}, {0., 1.5 + 1. - 0.5} {passox, passoy}, {0. passox, 3. passoy}}]
      , FaceForm[Transparent], EdgeForm[Black], Rectangle[{-0.2 passox, 0.5 passoy}, {0.9 passox, 2.6 passoy}]
      , AbsolutePointSize[4], Point[{{0, -passoy}, {0, 3 passoy}}]
      (*,Line[{{-0.2,-0.40}{passox,passoy},{0.1,-0.40}{passox,passoy},{0.1,-0.15}{passox,passoy}}]*)
      };
    contnatermmodelo = {Opacity[1], Line[{{0, -passoy}, {-0.5 passox, 0 passoy}}], Line[{{-0.25 passox, -0.5 passoy}, {-0.8 passox, -0.5 passoy}, {-0.8 passox, -0.2 passoy}, {-1.2 passox, -0.2 passoy}, {-1.2 passox, -0.5 passoy}, {-1.6 passox, -0.5 passoy}}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, 0}}]
      (*,FaceForm[Transparent],EdgeForm[Transparent],Rectangle[{-passox,-passoy},{passox,passoy}]*)
      };
    contnftermmodelo = {Opacity[1], Line[{{0, -passoy}, {0.5 passox, 0 passoy}, {0 passox, 0 passoy}}], Line[{{0.25 passox, -0.5 passoy}, {-0.55 passox, -0.5 passoy}, {-0.55 passox, -0.2 passoy}, {-0.95 passox, -0.2 passoy}, {-0.95 passox, -0.5 passoy}, {-1.35 passox, -0.5 passoy}}], AbsolutePointSize[4], Point[{{0, -passoy}, {0, 0}}]
      (*,FaceForm[Transparent],EdgeForm[Transparent],Rectangle[{-passox,-passoy},{passox,passoy}]*)
      };
    carga3fmodelo = {Opacity[1], EdgeForm[Black], FaceForm[Transparent], Rectangle[{-3. passox, -1.7 passoy}, {3. passox, 1.7 passoy}](*,Text["Carga\ntrifásica",{0,0}]*), Line[{{-2.2 passox, 1.7 passoy}, {-2.2 passox, 2.5 passoy}}], Line[{{0 passox, 1.7 passoy}, {0 passox, 2.5 passoy}}], Line[{{2.2 passox, 1.7 passoy}, {2.2 passox, 2.5 passoy}}], AbsolutePointSize[4], Point[{{-2.2 passox, 2.5 passoy}, {0 passox, 2.5 passoy}, {2.2 passox, 2.5 passoy}}]};
    p = 10 {10, 2.2}; pp1 = {0.4 tamanho[[1]], -4}; pp2 = {0.6 tamanho[[1]], -4};
    
    operacaoedicao = With[{passox = passox, passoy = passoy}, Graphics[{Lighter[Orange, 0.8], Rectangle[{0, -20}, {tamanho[[1]], 15}], Black
        , Dynamic@If[run
          , {Inset[Button["Edição", run = ! run, Appearance -> Automatic, Enabled -> True, ImageSize -> p], pp1, {1, 0}, {Automatic, 2 passoy}]
           , Inset[Button["Operação", run = ! run, Appearance -> "Pressed", Enabled -> False, ImageSize -> p, Background -> Lighter[Gray, 0.3]], pp2, {-1, 0}, {Automatic, 2 passoy}]}
          , {Inset[Button["Edição", run = ! run, Appearance -> "Pressed", Enabled -> False, ImageSize -> p, Background -> Lighter[Gray, 0.3]], pp1, {1, 0}, {Automatic, 2 passoy}]
           , Inset[Button["Operação", (
              run = ! run;
              
              (* As listas confconfconvertices, confconfarestas e confcargas são utilizadas em modo de edição; *)
              (* As listas confvertices, confarestas e cargas são utilizadas no modo operação*)
              confvertices = confconfvertices;
              confarestas = confconfarestas;
              cargas = confcargas;
              
              (*verifica quais vertices coincidem,para eliminar as duplicatas*)(*varre o vetor de vertices*)
              If[Length@confvertices > 0,
               (
                verticescoincidentesidx = {};
                verticescoincidentes = {};
                
                (* constrói uma lista em que, em cada linha, são indicados os vertices que se referem às mesmas coordenadas *)
                (* será mantido somente o primeiro vértice *)
                Do[(
                  aux = Position[confvertices, confvertices[[c, 2]]];
                  Which[Length@aux > 1, (
                    verticescoincidentesidx = Append[verticescoincidentesidx, aux[[;; , {1}]]];
                    verticescoincidentes = Append[verticescoincidentes, Extract[confvertices[[;; , 1]], aux[[;; , {1}]]]];
                    )];
                  ), {c, 1, Length@confvertices}];
                
                Do[(
                  temparestas = {};
                  Do[(
                    aux = Position[confarestas, verticescoincidentes[[c1, c2]]];
                    Which[Length@aux > 0, temparestas = Join[temparestas, aux]];
                    ), {c2, 2, Length[verticescoincidentes[[c1]]]}];
                  confarestas = ReplacePart[confarestas, temparestas -> verticescoincidentes[[c1, 1]]];
                  ), {c1, 1, Length@verticescoincidentes}];
                
                confvertices = Delete[confvertices, Transpose@{Flatten[verticescoincidentesidx[[;; , 2 ;;]], 2]}];
                (* Acerta as coordenadas dos vertices *)
                (* Divide pelos passos x e y, e subtrai dos minimos x e y *)
                
                confvertices[[;; , 2]] = Transpose@{confvertices[[;; , 2, 1]]/passox, confvertices[[;; , 2, 2]]/passoy};
                minx = Min@(confvertices[[;; , 2, 1]]);
                miny = Min@(confvertices[[;; , 2, 2]]);
                confvertices[[;; , 2]] = Transpose@{confvertices[[;; , 2, 1]] - minx, confvertices[[;; , 2, 2]] - miny};
                maxx = Max@(confvertices[[;; , 2, 1]]);
                maxy = Max@(confvertices[[;; , 2, 2]]);
                (*(* Acrescenta um vertice solto, dummy, só para criar um limite para o grafo, evitando o "tremido" *)
                AppendTo[confvertices,{10000,{maxx+3,maxy+3}}];
                *)
                
                (* Acrescenta dois vertices nos extremos da figura, para não tremer e dar a mesma proporção para todos os circuitos *)
                AppendTo[confvertices, {10001, {-5, -5}}];
                AppendTo[confvertices, {10002, {50, 27}}];
                
                )];
              
              (* Linhas a seguir se destinam à inicialização do Animate dos grafos *)
              circ = Graph[{}, {}];
              $HistoryLength = 0;
              ClearAll[aberto, animacarga3f, apertoubotna, apertoubotnf, arestas, arestasbobcont, arestassensterm, arestastempon, aux, auxarestas, auxbobina, auxlabel, b, bobcont
               , bobina, c, c2, caminho, circ, cont, contatos, contna, contnatempon, contnaterm, contnf, contnftempon, contnfterm, f, fechado, figurasvertices, gerafig, guardaimagens, histtemp, labelarestas, labelbobcont, labelbotna, labelbotnf, labelchave, labelcontna, labelcont, nasensterm, labelcontnatempon, labelcontnaterm, labelcontnf, labelcontnftempon, labelcontnfterm, labelfio, labelfusivel, labellamp, labeltempon, ligado, mostralabelvertices, n, numframesbobna, numframesbobnf, optmostralabelvertices, p1, p11, p12, p13, p14, p15, p16, p17, p18, p2, p3, p4, p5, pesoarestas, posvertices, potencial, r1, r2, resetterm, Resolution, saida2, tamanhovertices, tamfigura, tempon, termico, textosarestas, tiposarestas, tiposbobinas, vert1bob, vert2bob, vertices, x];
              
              ClearAll["frame*"];
              ClearAll["x*"];
              
              ), Appearance -> Automatic, Enabled -> True, ImageSize -> p], pp2, {-1, 0}, {Automatic, 2 passoy}]}
          ]}, ImageSize -> {1.05 tamanho[[1]], 40}, PlotRangePadding -> None]];
    figbarra = Graphics[{Black
       , Tooltip[EventHandler[Inset[Graphics@bobcontmodelo, {7. passox, 1. passoy}, {-1, -1}, {1 passox, Automatic}], {{"MouseClicked", 1} :> (Module[{tempvert}, (
              tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
              (*Descobre quantos elementos deste tipo já existem*)
              (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
              AppendTo[confconfarestas, {tempvert, "bobcont", "C" <> ToString@(ToExpression@StringDrop[
                    If[Length@listnomebobcont > 0, Last@listnomebobcont, "x0"]
                    , 1] + 1)}];
              pos1 = {5 passox, barra + 3 passoy};
              AppendTo[confconfvertices, {tempvert[[1]], pos1}];
              pos2 = {5 passox, barra + 1 passoy};
              AppendTo[confconfvertices, {tempvert[[2]], pos2}]
              (*achou[numbobcont+1]=False;*)
              )])}], "Bobina de contator"]
       , Tooltip[EventHandler[Inset[Graphics@temponmodelo, {8.5 passox, 1. passoy}, {-1, -1}, {1 passox, 1 passoy}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
            AppendTo[confconfarestas, {tempvert, "tempon", "D" <> ToString@(ToExpression@StringDrop[
                    If[Length@listnometempon > 0, Last@listnometempon, "x0"]
                    , 1] + 1), 10}];
            pos1 = {5 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numbobcont+1]=False;*)
            )}], "Bobina de temporizador na energização"]
       , Tooltip[EventHandler[Inset[Graphics@contnamodelo, {10. passox, 1.25 passoy}, {-1, -1.}, {0.4 passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numcontna=Length@Position[confconfarestas[[;;,2]],"contna"];*)
            AppendTo[confconfarestas, {tempvert, "contna", If[Length@Flatten@Join[{listnomebobcont, listnometempon}] > 0, First@Flatten@Join[{listnomebobcont, listnometempon}], ""]}];
            (**)
            pos1 = {5 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numcontna+1]=False;*)
            )}], "Contato N.A."]
       , Tooltip[EventHandler[Inset[Graphics@contnfmodelo, {11. passox, 1.25 passoy}, {-1, -1}, {0.4 passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numcontna=Length@Position[confconfarestas[[;;,2]],"contna"];*)
            AppendTo[confconfarestas, {tempvert, "contnf", If[Length@Flatten@Join[{listnomebobcont, listnometempon}] > 0, First@Flatten@Join[{listnomebobcont, listnometempon}], ""]}];
            (**)
            pos1 = {5 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numcontna+1]=False;*)
            )}], "Contato N.F."]
       , Tooltip[EventHandler[Inset[Graphics@botnamodelo, {12.5 passox, 1.27 passoy}, {0, 0}, {0.6 passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
            AppendTo[confconfarestas, {tempvert, "botna", "B" <> ToString@(ToExpression@StringDrop[
                    If[Length@listnomebotna > 0, Last@listnomebotna, "x0"]
                    , 1] + 1)}];
            pos1 = {6 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {6 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numbobcont+1]=False;*)
            )}], "Botoeira N.A."]
       , Tooltip[EventHandler[Inset[Graphics@botnfmodelo, {13.8 passox, 1.25 passoy}, {-1, -1}, {0.8 passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
            AppendTo[confconfarestas, {tempvert, "botnf", "X" <> ToString@(ToExpression@StringDrop[
                    If[Length@listnomebotnf > 0, Last@listnomebotnf, "x0"]
                    , 1] + 1)}];
            pos1 = {6 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {6 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numbobcont+1]=False;*)
            )}], "Botoeira N.F."]
       , Tooltip[EventHandler[Inset[Graphics@lampmodelo, {15.5 passox, 1. passoy}, {-1, -1}, {0.5 passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
            AppendTo[confconfarestas, {tempvert, "lamp", "L" <> ToString@(ToExpression@StringDrop[
                    If[Length@listnomelamp > 0, Last@listnomelamp, "x0"]
                    , 1] + 1)}];
            pos1 = {6 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {6 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numbobcont+1]=False;*)
            )}], "Lâmpada"]
       , Tooltip[EventHandler[Inset[Graphics@fiomodelo, {27. passox, 1. passoy}, {-1, -1}, {Automatic, 1 passoy}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
            (*O zero aqui indica a posição do "cotovelo" do fio, se existir*)
            AppendTo[confconfarestas, {tempvert, "fio", 0}];
            pos1 = {5 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numbobcont+1]=False;*)
            )}], "fio"]
       , Tooltip[EventHandler[Inset[Graphics@fusivelmodelo, {26.0 passox, 1. passoy}, {-1, -1}, {1 passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
            AppendTo[confconfarestas, {tempvert, "fusivel"}];
            pos1 = {5 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numbobcont+1]=False;*)
            )}], "fusível"]
       , Tooltip[EventHandler[Inset[Graphics@contnasenstermmodelo, {17. passox, 0.6 passoy}, {0, 1}, {Automatic, 1.5 passoy}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numbobcont=Length@Position[confconfarestas[[;;,2]],"bobcont"];*)
            AppendTo[confconfarestas, {tempvert, "contnasensterm", If[Length@Flatten@Join[{listnomebobcont, listnometempon}] > 0, First@Flatten@Join[{listnomebobcont, listnometempon}], ""]}];
            pos1 = {5 passox, barra + 4 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 2 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numbobcont+1]=False;*)
            )}], "Sensor do elemento térmico\nacoplado a um contato principal de um contator"]
       , Tooltip[EventHandler[Inset[Graphics@contnatermmodelo, {19. passox, 1.25 passoy}, {-1, -1.}, {1. passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numcontna=Length@Position[confconfarestas[[;;,2]],"contna"];*)
            AppendTo[confconfarestas, {tempvert, "contnaterm", If[Length@Flatten@Join[{listnomebobcont, listnometempon}] > 0, First@Flatten@Join[{listnomebobcont, listnometempon}], ""]}];
            (**)
            pos1 = {5 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numcontna+1]=False;*)
            )}], "Contato N.A. do elemento térmico"]
       , Tooltip[EventHandler[Inset[Graphics@contnftermmodelo, {20.5 passox, 1.25 passoy}, {-1, -1.}, {1. passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2}, {1, 2}];
            (*Descobre quantos elementos deste tipo já existem*)
            (*numcontna=Length@Position[confconfarestas[[;;,2]],"contna"];*)
            AppendTo[confconfarestas, {tempvert, "contnfterm", If[Length@Flatten@Join[{listnomebobcont, listnometempon}] > 0, First@Flatten@Join[{listnomebobcont, listnometempon}], ""]}];
            (**)
            pos1 = {5 passox, barra + 3 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox, barra + 1 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            (*achou[numcontna+1]=False;*)
            )}], "Contato N.F. do elemento térmico"]
       , Tooltip[EventHandler[Inset[Graphics[{carga3fmodelo, Text["Carga\n(trifásica)", {0, 0}]}], {23.2 passox, 0.8 passoy}, {-1, -1.}, {3. passox, Automatic}], {{"MouseClicked", 1} :> (
            tempvert = If[Length@confconfvertices > 0, {Max@(confconfvertices[[;; , 1]]) + 1, Max@(confconfvertices[[;; , 1]]) + 2, Max@(confconfvertices[[;; , 1]]) + 3, Max@(confconfvertices[[;; , 1]]) + 4}, {1, 2, 3, 4}];
            AppendTo[confcargas, {tempvert[[1]], "carga3f", "carga" <> ToString@(ToExpression@StringDrop[
                    If[Length@listnomecargas > 0, Last@listnomecargas, "carga0"]
                    , 5] + 1), tempvert[[2 ;; 4]]}];
            pos1 = {5 passox, barra + 4 passoy};
            AppendTo[confconfvertices, {tempvert[[1]], pos1}];
            pos2 = {5 passox + 0.01, barra + 4 passoy};
            AppendTo[confconfvertices, {tempvert[[2]], pos2}];
            pos3 = {5 passox + 0.02, barra + 4 passoy};
            AppendTo[confconfvertices, {tempvert[[3]], pos3}];
            pos4 = {5 passox + 0.03, barra + 4 passoy};
            AppendTo[confconfvertices, {tempvert[[4]], pos4}];
            )}], "Carga trifásica"]
       
       
       }, ImageSize -> {0.67 tamanho[[1]], barra}];
    
    desenha := Dynamic[(
       (*Module[{saida,c},*)
       
       saida = {};
       
       (*listbobcont=confconfarestas[[ Position[confconfarestas[[;;,2]],"bobcont"] ]];*)
       listnomebobcont = confconfarestas[[ Flatten@Position[confconfarestas[[;; , 2]], "bobcont"]  , 3]];
       listnometempon = confconfarestas[[ Flatten@Position[confconfarestas[[;; , 2]], "tempon"]  , 3]];
       listnomebotna = confconfarestas[[ Flatten@Position[confconfarestas[[;; , 2]], "botna"]  , 3]];
       listnomebotnf = confconfarestas[[ Flatten@Position[confconfarestas[[;; , 2]], "botnf"]  , 3]];
       listnomebobinas = Flatten@Join[{listnomebobcont, listnometempon}];
       listnomelamp = confconfarestas[[ Flatten@Position[confconfarestas[[;; , 2]], "lamp"]  , 3]];
       listnomecargas = confcargas[[;; , 3]];
       
       If[(Length@confconfarestas) > 0,
        (
         Do[(
            vertice1 = confconfarestas[[c, 1, 1]];
            posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
            vertice2 = confconfarestas[[c, 1, 2]];
            posvertice2 = Position[confconfvertices[[;; , 1]], vertice2][[1]][[1]];
            
            Switch[confconfarestas[[c, 2]]
             , "bobcont",
             (
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                  {Inset[Graphics[{bobcontmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, passoy}, {Automatic, 4 passoy}]
                   , Text[Style[confconfarestas[[c, 3]] , {FontSize -> 11}], Dynamic[confconfvertices[[posvertice1, 2]] + {-1.5 passox, -0.5 passoy}]]
                   , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(*(cor[c]=Black)&*)Null, ((*cor[c]=Red;*)confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    (*cor[c]=Black;*)
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, 4 passoy};
                    ) &}], Graphics[{(*If[ValueQ[cor[c]],FaceForm[cor[c]],Black]*)Black, Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                  ]}];
              )
             , "contna",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{contnamodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {0.8 passox, Automatic(*4passoy*)}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(*(cor[c]=Black)&*)Null, ((*cor[c]=Red;*)confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    (*cor[c]=Black;*)
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{(*If[ValueQ[cor[c]],FaceForm[cor[c]],Black]*)Black, Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 3]], {Temporary, Temporary, (confconfarestas[[c, 3]] = #; If[StringStartsQ[#, "D"], confconfarestas[[c, 2]] = "contnatempon", {}]) &}]], listnomebobinas], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {2. passox, -0.7 passoy}, None]], {0, 0}]}];
              )
             , "contnf",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{contnfmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {0.8 passox, Automatic}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 3]], {Temporary, Temporary, (confconfarestas[[c, 3]] = #; If[StringStartsQ[#, "D"], confconfarestas[[c, 2]] = "contnftempon", {}]) &}]], listnomebobinas], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {2.5 passox, -0.7 passoy}, None]], {0, 0}]}];
              )
             , "contnatempon",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{contnamodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {0.8 passox, Automatic(*4passoy*)}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 3]], {Temporary, Temporary, (confconfarestas[[c, 3]] = #; If[StringStartsQ[#, "C"], confconfarestas[[c, 2]] = "contna", {}]) &}]], listnomebobinas], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {2. passox, -0.7 passoy}, None]], {0, 0}]}];
              )
             , "contnftempon",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{contnfmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {0.8 passox, Automatic}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 3]], {Temporary, Temporary, (confconfarestas[[c, 3]] = #; If[StringStartsQ[#, "C"], confconfarestas[[c, 2]] = "contnf", {}]) &}]], listnomebobinas], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {2.5 passox, -0.7 passoy}, None]], {0, 0}]}];
              )
             , "tempon",
             (
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{temponmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, passoy}, {Automatic, 4 passoy}]
                  , Text[Style[confconfarestas[[c, 3]] , {FontSize -> 11}], Dynamic[confconfvertices[[posvertice1, 2]] + {-1.5 passox, -0.5 passoy}]]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(*(cor[c]=Black)&*)Null, ((*cor[c]=Red;*)confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    (*cor[c]=Black;*)
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, 4 passoy};
                    ) &}], Graphics[{(*If[ValueQ[cor[c]],FaceForm[cor[c]],Black]*)Black, Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 4]]]], {5 -> "5 s", 10 -> "10 s", 15 -> "15 s", 30 -> "30 s"}], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {3.2 passox, -1 passoy}, None]], {0, 0}]}];
              )
             , "botna",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{botnamodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {1 passox, Automatic}]
                  , Text[Style[confconfarestas[[c, 3]] , {FontSize -> 11}], Dynamic[confconfvertices[[posvertice1, 2]] + {-1.0 passox, -0.7 passoy}], {1, 0}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                 ]}];
              (*AppendTo[saida,{
              Inset[PopupMenu[With[{c=c},Dynamic[confconfarestas[[c,3]]]],listnomebobinas],With[{posvertice1=posvertice1,c=c},Dynamic[confconfvertices[[Position[confconfvertices[[;;,1]],confconfarestas[[c,1,1]]][[1]][[1]],2]]+{3passox,-0.7passoy},None]],{0,0}]}];*)
              )
             , "botnf",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{botnfmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {1.2 passox, Automatic}]
                  , Text[Style[confconfarestas[[c, 3]] , {FontSize -> 11}], Dynamic[confconfvertices[[posvertice1, 2]] + {-1.0 passox, -0.7 passoy}], {1, 0}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                 ]}];
              (*AppendTo[saida,{
              Inset[PopupMenu[With[{c=c},Dynamic[confconfarestas[[c,3]]]],listnomebobinas],With[{posvertice1=posvertice1,c=c},Dynamic[confconfvertices[[Position[confconfvertices[[;;,1]],confconfarestas[[c,1,1]]][[1]][[1]],2]]+{3passox,-0.7passoy},None]],{0,0}]}];*)
              )
             , "lamp",
             (
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                  {Inset[Graphics[{lampmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, passoy}, {Automatic, 4 passoy}]
                   , Text[Style[confconfarestas[[c, 3]] , {FontSize -> 11}], Dynamic[confconfvertices[[posvertice1, 2]] + {-0.7 passox, -1.0 passoy}], {1, 0}]
                   , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, 4 passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                  ]}];
              )
             , "fio",
             (AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                  { Locator[Dynamic[confconfvertices[[posvertice1, 2]], {
                    (
                    delta[c] = Round[confconfvertices[[posvertice1, 2]] - confconfvertices[[posvertice2, 2]], {passox, passoy}];(*cor1[c]=Black*)
                    ) &
                    , ((*cor1[c]=Red;*)confconfvertices[[posvertice1, 2]] = #; confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - delta[c]
                    ) &
                    , (
                    (*cor1[c]=Black;*)
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - delta[c]
                    ) &}], Graphics[{(*If[ValueQ[cor1[c]],FaceForm[cor1[c]],Black]*)Black, Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]
                   , Locator[Dynamic[confconfvertices[[posvertice2, 2]], {(*(cor2[c]=Black)&*)Null,
                    ((*cor2[c]=Red;*)
                    deltatemp = confconfvertices[[posvertice1, 2]] - #;
                    delta[c] = If[Abs[deltatemp[[1]]] >= Abs[deltatemp[[2]]], {deltatemp[[1]], 0}, {0, deltatemp[[2]]}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - delta[c]
                    ) &
                    , (
                    (*cor2[c]=Black;*)
                    delta[c] = Round[confconfvertices[[posvertice1, 2]] - confconfvertices[[posvertice2, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - delta[c];
                    ) &}], Graphics[{(*If[ValueQ[cor2[c]],FaceForm[cor2[c]],Black]*)Black, Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]
                   , Line[{Dynamic[confconfvertices[[posvertice1, 2]]], Dynamic[confconfvertices[[posvertice2, 2]]]}]
                   , Disk[Dynamic[confconfvertices[[posvertice1, 2]]], 2], Lighter[Black, 0.5], Disk[Dynamic[confconfvertices[[posvertice2, 2]]], 2]}
                  ]}];
              )
             , "fusivel",
             (
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                  {Inset[Graphics[{fusivelmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {-passox, 0}, 1 {2 passox, 1 passoy}]
                   (*,Text[Style[confconfarestas[[c,3]] ,{FontSize->11}],Dynamic[confconfvertices[[posvertice1,2]]+{-0.7passox,-1.0passoy}],{1,0}]*)
                   , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] + {2 passox, 0};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large]}
                  ]}];
              
              )
             , "contnasensterm",
             (
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{contnasenstermmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 3 passoy}, {1.6 passox, Automatic}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, 4 passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 3]]]], listnomebobinas], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {2.5 passox, -0.7 passoy}, None]], {0, 0}]}];
              )
             , "contnaterm",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{contnatermmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {1.8 passox, Automatic(*4passoy*)}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 3]]]], listnomebobinas], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {2. passox, -0.7 passoy}, None]], {0, 0}]}];
              )
             , "contnfterm",
             (posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
              AppendTo[saida, {With[{posvertice1 = posvertice1, posvertice2 = posvertice2, c = c},
                 {Inset[Graphics[{contnftermmodelo}], Dynamic[confconfvertices[[posvertice1, 2]]], {0, 0 passoy}, {1.8 passox, Automatic(*4passoy*)}]
                  , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {(cor[c] = Black) &, (cor[c] = Red; confconfvertices[[posvertice1, 2]] = #) &
                    , (
                    cor[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] - {0, passoy};
                    ) &}], Graphics[{If[ValueQ[cor[c]], FaceForm[cor[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large]}
                 ]}];
              AppendTo[saida, {
                Inset[PopupMenu[With[{c = c}, Dynamic[confconfarestas[[c, 3]]]], listnomebobinas], With[{posvertice1 = posvertice1, c = c}, Dynamic[confconfvertices[[Position[confconfvertices[[;; , 1]], confconfarestas[[c, 1, 1]]][[1]][[1]], 2]] + {2.5 passox, -0.7 passoy}, None]], {0, 0}]}];
              )
             ];
            (*With[{posvertice1=posvertice1},confconfvertices[[posvertice1,2]]=Round[confconfvertices[[posvertice1,2]],{passox,passoy}]];
            With[{posvertice2=posvertice2},confconfvertices[[posvertice2,2]]=Round[confconfvertices[[posvertice2,2]],{passox,passoy}]];*)
            
            (*confconfvertices[[posvertice2,2]]=confconfvertices[[posvertice1,2]]-{0,2passoy};*)
            ), {c, 1, Length@confconfarestas}];
         )
        , {}];
       If[Length@listnomecargas > 0,
        Do[(
           vertice1 = confcargas[[c, 4, 1]];
           posvertice1 = Position[confconfvertices[[;; , 1]], vertice1][[1]][[1]];
           vertice2 = confcargas[[c, 4, 2]];
           posvertice2 = Position[confconfvertices[[;; , 1]], vertice2][[1]][[1]];
           vertice3 = confcargas[[c, 4, 3]];
           posvertice3 = Position[confconfvertices[[;; , 1]], vertice3][[1]][[1]];
           vertice0 = confcargas[[c, 1]];
           posvertice0 = Position[confconfvertices[[;; , 1]], vertice0][[1]][[1]];
           Switch[confcargas[[c, 2]]
            , "carga3f",
            (With[{posvertice1 = posvertice1, posvertice2 = posvertice2, posvertice3 = posvertice3, posvertice0 = posvertice0, c = c}, (
               AppendTo[saida, {
                  {Inset[Graphics[{carga3fmodelo, , Text["Carga " <> StringDrop[confcargas[[c, 3]], 5] <> "\n(trifásica)", {0, 0}]}], Dynamic[confconfvertices[[posvertice1, 2]]], {-2 passox, 2.5 passoy}, {6. passox, Automatic}]
                   , Locator[Dynamic[confconfvertices[[posvertice1, 2]], {
                    (
                    corc[c] = Black
                    ) &
                    , (
                    corc[c] = Red; confconfvertices[[posvertice1, 2]] = #
                    ) &
                    , (
                    corc[c] = Black;
                    confconfvertices[[posvertice1, 2]] = Round[confconfvertices[[posvertice1, 2]], {passox, passoy}];
                    confconfvertices[[posvertice2, 2]] = confconfvertices[[posvertice1, 2]] + {2 passox, 0};
                    confconfvertices[[posvertice3, 2]] = confconfvertices[[posvertice1, 2]] + {4 passox, 0};
                    confconfvertices[[posvertice0, 2]] = confconfvertices[[posvertice1, 2]] + {2 passox, -passoy};
                    ) &}], Graphics[{If[ValueQ[corc[c]], FaceForm[corc[c]], Black], Disk[{0, 0}, Scaled[0.15]]}], ImageSize -> Large, ContinuousAction -> False]}
                  }];
               )]
             )]), {c, 1, Length@confcargas}];, {}];
       Do[With[{c = c},
         (AppendTo[saida,
            {Locator[
              Dynamic[confconfvertices[[c, 2]], {
                (*(
                corf[c]=Black
                )&*)Null
                ,(*(
                corf[c]=Red;*)(confconfvertices[[c, 2]] = #
                  ) &
                , (
                  (*corf[c]=Black;*)
                  confconfvertices[[c, 2]] = Round[confconfvertices[[c, 2]], {passox, passoy}];
                  ) &}], Graphics[{(*If[ValueQ[corf[c]],FaceForm[corf[c]],Black]*)Black, Disk[{0, 0}, Scaled[0.2]]}], ImageSize -> Large, ContinuousAction -> False], Opacity[1], Black,
             Dynamic@Text[Switch[c, 1, "Fase A\n(Comando)", 2, "Fase B\n(Comando)", 3, "Fase A\n(Potência)", 4, "Fase B\n(Potência)", 5, "Fase C\n(Potência)"], confconfvertices[[c, 2]] + {-0.5*passox, 0}, {1, 0}]
             }];
          )], {c, 1, 5}];
       saida)
      , TrackedSymbols :> {confconfvertices[[;; , 1]], confconfarestas, confcargas, escolhapreconf}];
    
    edita = Graphics[{Lighter[Green, 0.8], Rectangle[{3 passox, 0}, tamanho], {EdgeForm[{Black, Dashing[0.005]}], FaceForm[Transparent], lixeira}, Black, Text["lixeira", 0.5 (lixeira[[1]] + lixeira[[2]])](*,If[!run,Point[z],{}]*)(*,
       Inset[operacaoedicao,{passox,passoy},{-1,-1},{Automatic,4passoy},Background->Transparent]*)
       , Dynamic[If[! run, Inset[figbarra, {passox, passoy}, {-1, -1}, {Automatic, 8 passoy}, Background -> Transparent], {}], TrackedSymbols :> {run}](*,Inset[fig1,fig1pos,{-1,-1},fig1tam]*)(*,Inset[EventHandler[fig1,{"MouseDragged":>(
       fig1pos=Nearest[z,MousePosition["Graphics"]][[1]];
       )}],Dynamic@fig1pos,{-1,-1},fig1tam]*)
       
       , {Black,(*Text["Circuitos pré-configurados",{56passox,46passoy}],*)EdgeForm[Lighter[Black, 0.8]], FaceForm[Transparent], Rectangle[{70 passox, 64 passoy}, {98 passox, 69 passoy}]
        , Inset[PopupMenu[
          Dynamic[escolhapreconf
           , {(
              preconfconfvertices[escolhapreconf] = confconfvertices;
              preconfconfarestas[escolhapreconf] = confconfarestas;
              preconfcargas[escolhapreconf] = confcargas;
              ) &
            , (escolhapreconf = #;
              confconfvertices = preconfconfvertices[escolhapreconf];
              confconfarestas = preconfconfarestas[escolhapreconf];
              confcargas = preconfcargas[escolhapreconf];
              ) &
            }]
          , listpreconf, FieldSize -> {21, 1}], {55 passox, 48 passoy}]}
       
       , Text[Style[Dynamic[Replace[escolhapreconf, listpreconf]], {FontSize -> 16, FontWeight -> Bold}], {10 passox, 69 passoy}, {-1, 1}], Inset[botlixeira, {Max[lixeira[[1, 1]], lixeira[[2, 1]]] + 10, 0.5 lixeira[[1, 2]] + 0.5 lixeira[[2, 2]]}, {-1, 0}]
       , desenha
       , Inset[Button[Style["Copia\npré-configurações", {TextAlignment -> Center}]
         , (
          
          (*Atualiza o circuito exibido no momento*)
          preconfconfvertices[escolhapreconf] = confconfvertices;
          preconfconfarestas[escolhapreconf] = confconfarestas;
          preconfcargas[escolhapreconf] = confcargas;
          
          (*Exportar para arquivo-texto*)
          (*exportConf={"(* Pré-configurações em "<>StringReplace[DateString[LocalTime[]],":"->"-"]<>" *)"};
          Do[(
          AppendTo[exportConf,"\npreconfconfvertices["<>ToString[c]<>"]="<>ToString@preconfconfvertices[c]<>";"];
          
          aux1=Position[preconfconfarestas[c],_?StringQ];
          aux2=Extract[preconfconfarestas[c],aux1];
          Do[aux2[[m]]="\""<>aux2[[m]]<>"\"",{m,1,Length@aux2}];
          aux3=preconfconfarestas[c];
          Do[(aux3=ReplacePart[aux3,aux1[[m]]->aux2[[m]]]),{m,1,Length@aux1}];
          AppendTo[exportConf,"\npreconfconfarestas["<>ToString[c]<>"]="<>ToString@aux3<>";"];
          
          aux1=Position[preconfcargas[c],_?StringQ];
          aux2=Extract[preconfcargas[c],aux1];
          Do[aux2[[m]]="\""<>aux2[[m]]<>"\"",{m,1,Length@aux2}];
          aux3=preconfcargas[c];
          Do[(aux3=ReplacePart[aux3,aux1[[m]]->aux2[[m]]]),{m,1,Length@aux1}];
          AppendTo[exportConf,"\npreconfcargas["<>ToString[c]<>"]="<>ToString@aux3<>";"];
          
          AppendTo[exportConf,"\ncomentario["<>ToString[c]<>"]=\""<>If[StringQ[comentario[c]],comentario[c],"  "]<>"\";"];
          ),{c,1,Length@listpreconf}];
          Export[NotebookDirectory[]<>"Simulador-contator-preconf-"<>StringReplace[DateString[LocalTime[]],":"->"-"]<>".txt",exportConf,"List"];*)
          
          (*Copiar para área de transferência*)
          copyConf = {"(* Pré-configurações em " <> StringReplace[DateString[LocalTime[]], ":" -> "-"] <> " *)"};
          Do[(
            AppendTo[copyConf, "\n \n(*Circuito " <> ToString[c] <> ":*)"];
            AppendTo[copyConf, "\npreconfconfvertices[" <> ToString[c] <> "]=" <> ToString@preconfconfvertices[c] <> ";"];
            AppendTo[copyConf, "\n"];
            
            aux1 = Position[preconfconfarestas[c], _?StringQ];
            aux2 = Extract[preconfconfarestas[c], aux1];
            Do[aux2[[m]] = "\"" <> aux2[[m]] <> "\"", {m, 1, Length@aux2}];
            aux3 = preconfconfarestas[c];
            Do[(aux3 = ReplacePart[aux3, aux1[[m]] -> aux2[[m]]]), {m, 1, Length@aux1}];
            AppendTo[copyConf, "\npreconfconfarestas[" <> ToString[c] <> "]=" <> ToString@aux3 <> ";"];
            AppendTo[copyConf, "\n"];
            
            aux1 = Position[preconfcargas[c], _?StringQ];
            aux2 = Extract[preconfcargas[c], aux1];
            Do[aux2[[m]] = "\"" <> aux2[[m]] <> "\"", {m, 1, Length@aux2}];
            aux3 = preconfcargas[c];
            Do[(aux3 = ReplacePart[aux3, aux1[[m]] -> aux2[[m]]]), {m, 1, Length@aux1}];
            AppendTo[copyConf, "\npreconfcargas[" <> ToString[c] <> "]=" <> ToString@aux3 <> ";"];
            AppendTo[copyConf, "\n"];
            
            AppendTo[copyConf, "\ncomentario[" <> ToString[c] <> "]=\"" <> If[StringQ[comentario[c]], comentario[c], "  "] <> "\";"];
            ), {c, 1, Length@listpreconf}];
          
          CopyToClipboard@StringRiffle[copyConf];
          MessageDialog["Pré-configurações copiadas para a área de transferência. Caso deseje, abra a versão editável desse notebook para acrescentar mais circuitos."];
          )
         ], {7 passox, 3 passoy}]}, PlotRangePadding -> None, PlotRangeClipping -> True, ImageMargins -> 0, ImageSize -> {1.06, 1.1} tamanho, PlotRange -> {{3. passox, tamanho[[1]]}, {0, tamanho[[2]]}}
      
      ];
    
    (*Graphics[{Lighter[Green,0.8],Rectangle[{0,0},tamanho],Black,Point[z],Inset[fig1,fig1pos,{-1,-1},fig1tam],Inset[EventHandler[fig1,{"MouseDragged":>(
    fig1pos=Nearest[z,MousePosition["Graphics"]][[1]];
    )}],Dynamic@fig1pos,{-1,-1},fig1tam]},ImageSize->Full,PlotRange->{{0,tamanho[[1]] },{0,tamanho[[2]] }}]*)
    opera = Animate[(
       optmostralabelvertices = If[mostralabelvertices == True, "Name", None];
       pesoarestas = Table[Null, {cont, 1, Length@arestas}];
       For[cont = 1, cont <= Length@arestas, cont++, (
         Which[
           tiposarestas[[cont]] == "fio", pesoarestas[[cont]] = fechado;,
           tiposarestas[[cont]] == "fusivel", pesoarestas[[cont]] = fechado;,
           tiposarestas[[cont]] == "botnf", (
            Which[((apertoubotnf[[cont, 1]] == aberto) && ((frame - apertoubotnf[[cont, 2]]) > numframesbobnf)),
             (apertoubotnf[[cont, 1]] = fechado;
              apertoubotnf[[cont, 2]] = frame;), True, Null];
            pesoarestas[[cont]] = apertoubotnf[[cont, 1]];
            ),
           tiposarestas[[cont]] == "botna", (
            Which[((apertoubotna[[cont, 1]] == fechado) && ((frame - apertoubotna[[cont, 2]]) > numframesbobna)),
             (apertoubotna[[cont, 1]] = aberto;
              apertoubotna[[cont, 2]] = frame;), True, Null];
            pesoarestas[[cont]] = apertoubotna[[cont, 1]];
            ),
           tiposarestas[[cont]] == "bobcont", pesoarestas[[cont]] = bobina;,
           tiposarestas[[cont]] == "tempon", pesoarestas[[cont]] = bobina;,
           tiposarestas[[cont]] == "contna", pesoarestas[[cont]] = contna[cont];,
           tiposarestas[[cont]] == "contnf", pesoarestas[[cont]] = contnf[cont];,
           tiposarestas[[cont]] == "contnasensterm", pesoarestas[[cont]] = contna[cont];,
           tiposarestas[[cont]] == "contnatempon", pesoarestas[[cont]] = contnatempon[cont];,
           tiposarestas[[cont]] == "contnftempon", pesoarestas[[cont]] = contnftempon[cont];,
           tiposarestas[[cont]] == "contnfterm", pesoarestas[[cont]] = contnfterm[cont];,
           tiposarestas[[cont]] == "contnaterm", pesoarestas[[cont]] = contnaterm[cont];,
           tiposarestas[[cont]] == "lamp", pesoarestas[[cont]] = bobina];
         )];
       
       For[cont = 1, cont <= Length@arestas, cont++, (
         auxlabel = "label" <> tiposarestas[[cont]] <> "[" <> ToString@cont <> "]";
         labelarestas[[cont]] = arestas[[cont]] -> ToExpression@(auxlabel);
         )];
       
       Do[Which[
         cargas[[cont, 2]] == "carga3f", (
          figurasvertices[[cont]] = (cargas[[cont, 1]] -> animacarga3f[ cargas[[cont]] ]);
          tamanhovertices[[cont]] = (cargas[[cont, 1]] -> 3 {1, 1});
          )
         ], {cont, 1, Length@cargas}];
       
       circ = Graph[vertices, arestas, VertexCoordinates -> posvertices, VertexLabels -> optmostralabelvertices, EdgeWeight -> pesoarestas, EdgeLabels -> labelarestas, EdgeStyle -> Thickness[0.003], VertexShape -> figurasvertices, VertexSize -> tamanhovertices];
       
       Do[(
         aux = {};
         caminho[f] = Graph[{}, {}];
         Do[(
           aux = FindPath[circ, f, vertices[[c]], 100, All];
           If[Length[aux] > 0, (
             Do[
              (caminho[f] = GraphUnion[caminho[f], PathGraph[aux[[c2]]]];), {c2, 1, Length[aux]}])
            , Null]
           ), {c, 1, Length@vertices}];
         ), {f, {verticeF1, verticeF2, verticeP1, verticeP2, verticeP3}}];
       saida2 = HighlightGraph[circ, {caminho[verticeF1], caminho[verticeF2], caminho[verticeP1], caminho[verticeP2], caminho[verticeP3]}, ImageSize -> tamfigura];
       Which[gerafig == True, guardaimagens[[2*frame]] = saida2];
       Pane[saida2, tamfigura]
       
       ), {frame, 1., 200000., 1.},
      Initialization :> (
        (* Trecho a seguir foi transferido para o botão de 'operação' *)
        (*circ=Graph[{},{}];
        $HistoryLength=0;
        ClearAll[aberto,animacarga3f,apertoubotna,apertoubotnf,arestas,arestasbobcont,arestassensterm,arestastempon,aux,auxarestas,auxbobina,auxlabel,b,bobcont
        ,bobina,c,c2,caminho,cargas,circ,confarestas,confvertices,cont,contatos,contna,contnatempon,contnaterm,contnf,contnftempon,contnfterm,f,fechado,figurasvertices,gerafig,guardaimagens,histtemp,labelarestas,labelbobcont,labelbotna,labelbotnf,labelchave,labelcontna,labelcontnasensterm,labelcontnatempon,labelcontnaterm,labelcontnf,labelcontnftempon,labelcontnfterm,labelfio,labelfusivel,labellamp,labeltempon,ligado,mostralabelvertices,n,numframesbobna,numframesbobnf,optmostralabelvertices,p1,p11,p12,p13,p14,p15,p16,p17,p18,p2,p3,p4,p5,pesoarestas,posvertices,potencial,r1,r2,resetterm,Resolution,saida2,tamanhovertices,tamfigura,tempon,termico,textosarestas,tiposarestas,tiposbobinas,vert1bob,vert2bob,verticeF1,verticeF2,verticeP1,verticeP2,verticeP3,vertices,x];ClearAll["frame*"];ClearAll["x*"];*)
        
        labelfio[x_] := ("");
        labelfusivel[x_] := (
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          r1 = p1 - {0, 0.5*Norm[p2 - p1]};
          r2 = p2 + {0, 0.5*Norm[p2 - p1]};
          p3 = {Min[p1[[1]], p2[[1]]], p1[[2]]} + {0.125, 0.25}*Norm[p2 - p1];
          p4 = {Max[p1[[1]], p2[[1]]], p1[[2]]} + {-0.125, -0.25}*Norm[p2 - p1];
          Graphics[{EdgeForm[Black], FaceForm[Transparent], Rectangle[p3, p4]}, ImageSize -> {15, 15}]
          );
        labelcontna[x_] := (
          auxbobina = confarestas[[x, 3]];
          vert1bob = bobcont[auxbobina][[1]];
          vert2bob = bobcont[auxbobina][[2]];
          contna[x] = If[(potencial[vert1bob] == "F1" && potencial[vert2bob] == "F2") || (potencial[vert1bob] == "F2" && potencial[vert2bob] == "F1"), fechado, aberto];
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {-0.5, 0.75}*Norm[p2 - p1];
          r1 = p1 - {.8*Norm[p2 - p1], 0};
          r2 = p2 + {.8*Norm[p2 - p1], 0};
          If[contna[x] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])}, {1, 0}]}, ImageSize -> {2., 1.} {30, 30}], If[contna[x] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])}, {1, 0}]}, ImageSize -> {60, 30}], "??"]]
          );
        labelcontnf[x_] := (
          auxbobina = confarestas[[x, 3]];
          vert1bob = bobcont[auxbobina][[1]];
          vert2bob = bobcont[auxbobina][[2]];
          contnf[x] = If[(potencial[vert1bob] == "F1" && potencial[vert2bob] == "F2") || (potencial[vert1bob] == "F2" && potencial[vert2bob] == "F1"), aberto, fechado];
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.35, 1.}*Norm[p2 - p1];
          p4 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.5, 0.9}*Norm[p2 - p1];
          r1 = p1 - {0.8*Norm[p2 - p1], 0};
          r2 = p2 + {0.8*Norm[p2 - p1], 0};
          If[contnf[x] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p3}], Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p4}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r1[[1]], 0.5*(r1[[2]] + r2[[2]])}, {-1, 0}]}, ImageSize -> {60, 30}], If[contnf[x] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p3}], Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r1[[1]], 0.5*(r1[[2]] + r2[[2]])}, {-1, 0}]}, ImageSize -> {60, 30}], "??"]]
          );
        labelbobcont[x_] := (
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          r1 = p1 - {0.5*Norm[p2 - p1], 0};
          r2 = p2 + {0.5*Norm[p2 - p1], 0};
          p3 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {-0.5, -0.25}*Norm[p2 - p1];
          p4 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.5, 0.25}*Norm[p2 - p1];
          If[(potencial[arestas[[x, 1]]] == "F1" && potencial[arestas[[x, 2]]] == "F2") || (potencial[arestas[[x, 1]]] == "F2" && potencial[arestas[[x, 2]]] == "F1"),
           Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], EdgeForm[Black], FaceForm[Red], Rectangle[p3, p4], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], 0.5*(p1 + p2), {0, 0}]}, ImageSize -> {45, 45}],
           Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], EdgeForm[Black], FaceForm[White], Rectangle[p3, p4], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], 0.5*(p1 + p2), {0, 0}]}, ImageSize -> {45, 45}]]
          );
        labelcontnasensterm[x_] := (
          auxbobina = confarestas[[x, 3]];
          vert1bob = bobcont[auxbobina][[1]];
          vert2bob = bobcont[auxbobina][[2]];
          contna[x] = If[(potencial[vert1bob] == "F1" && potencial[vert2bob] == "F2") || (potencial[vert1bob] == "F2" && potencial[vert2bob] == "F1"), fechado, aberto];
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + 0.5*{-0.5, 0.75}*Norm[p2 - p1];
          r1 = p1 - {0.25*Norm[p2 - p1], 0};
          r2 = p2 + {0.25*Norm[p2 - p1], 0};
          p11 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {0., -0.22}*Norm[p2 - p1];
          p12 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {-0.105, -0.22}*Norm[p2 - p1];
          p13 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {-0.105, -0.33}*Norm[p2 - p1];
          p14 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {0., -0.33}*Norm[p2 - p1];
          p15 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {-0.2, -0.15}*Norm[p2 - p1];
          p16 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {-0.2, -0.40}*Norm[p2 - p1];
          p17 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {0.1, -0.40}*Norm[p2 - p1];
          p18 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {0.1, -0.15}*Norm[p2 - p1];
          Grid[{{Style[textosarestas[[x]], FontFamily -> "Courier New"], If[contna[x] == aberto, Button[Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}], Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p11, p12, p13, p14, { p1[[1]], 0.5*(p1[[2]] + p2[[2]])}}],
                 Line[{p15, p16, p17, p18, p15}]}, ImageSize -> {20, 40}]], If[contna[x] == fechado, Button[Graphics[{White, Rectangle[r1, r2], Black, Line[{0.5*(p1 + p2), {p1[[1]], Min[p1[[2]], p2[[2]]]}}], Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p11, p12, p13, p14, { p1[[1]], 0.5*(p1[[2]] + p2[[2]])}}],
                  Line[{p15, p16, p17, p18, p15}]}, ImageSize -> {20, 40}], (auxbobina = confarestas[[x, 3]];
                 termico[auxbobina] = "atuado";
                 contatos = Intersection[Position[confarestas, "contnfterm"][[;; , 1]] , b = Position[confarestas, textosarestas[[x]]][[;; , 1]] ];
                 Do[resetterm[[(contatos[[n]])]] = -1, {n, 1, Length@contatos}];
                 )]], "??"], Style[StringReplace[textosarestas[[x]], _ -> " "], FontFamily -> "Courier New"]}}, Spacings -> 0]
          );
        labelcontnfterm[x_] := Grid[{{Style[DisplayForm[FractionBox["T", textosarestas[[x]] ] ], FontFamily -> "Courier New", FontSize -> 8], Button[(
              auxbobina = confarestas[[x, 3]];
              vert1bob = bobcont[auxbobina][[1]];
              vert2bob = bobcont[auxbobina][[2]];
              contnfterm[x] = If[termico[auxbobina] == "atuado", aberto, fechado];
              Which[resetterm[[x]] == 1 && termico == "normal", resetterm[[x]] = 0, True, Null];
              p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
              p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
              p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.35, 1.}*Norm[p2 - p1];
              p4 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.5, 0.9}*Norm[p2 - p1];
              r1 = p1 - {0.5*Norm[p2 - p1], 0};
              r2 = p2 + {0.5*Norm[p2 - p1], 0};
              Which[contnfterm[x] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p3}], Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p4}]}, ImageSize -> {15, 15}], contnfterm[x] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p3}], Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}]}, ImageSize -> {15, 15}], True, "??"]),
             (Which[contnfterm[x] == aberto,
               (resetterm[[x]] = 1;
                auxbobina = confarestas[[x, 3]];
                termico[auxbobina] = "normal";)]
              )], "   "}}];
        labelcontnaterm[x_] := (
          auxbobina = confarestas[[x, 3]];
          vert1bob = bobcont[auxbobina][[1]];
          vert2bob = bobcont[auxbobina][[2]];
          contnaterm[x] = If[termico[auxbobina] == "atuado", fechado, aberto];
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {-0.5, 0.75}*Norm[p2 - p1];
          r1 = p1 - {0.8*Norm[p2 - p1], 0};
          r2 = p2 + {0.8*Norm[p2 - p1], 0};
          If[contnaterm[x] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}], Text[Style[DisplayForm[FractionBox["T", textosarestas[[x]] ] ], FontFamily -> "Courier New", FontSize -> 8], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])}, {1, 0}]}, ImageSize -> {60, 30}], If[contnaterm[x] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], Text[Style[DisplayForm[FractionBox["T", textosarestas[[x]] ] ], FontFamily -> "Courier New", FontSize -> 8], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])}, {1, 0}]}, ImageSize -> {60, 30}], "??"]]
          );
        labellamp[x_] := (
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          r1 = p1 - {0.5*Norm[p2 - p1], 0};
          r2 = p2 + {0.5*Norm[p2 - p1], 0};
          If[(potencial[arestas[[x, 1]]] == "F1" && potencial[arestas[[x, 2]]] == "F2") || (potencial[arestas[[x, 1]]] == "F2" && potencial[arestas[[x, 2]]] == "F1"),
           Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], EdgeForm[Black], FaceForm[Red], Disk[0.5*(p1 + p2), 0.5], Line[{{-0.5*Sqrt[0.5], -0.5*Sqrt[0.5]} + 0.5*(p1 + p2), {0.5*Sqrt[0.5], 0.5*Sqrt[0.5]} + 0.5*(p1 + p2)}], Line[{{-0.5*Sqrt[0.5], 0.5*Sqrt[0.5]} + 0.5*(p1 + p2), {0.5*Sqrt[0.5], -0.5*Sqrt[0.5]} + 0.5*(p1 + p2)}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])} + {-0.1, -0.7}, {1, 0}]}, ImageSize -> {45, 45}],
           Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], EdgeForm[Black], FaceForm[White], Disk[0.5*(p1 + p2), 0.5], Line[{{-0.5*Sqrt[0.5], -0.5*Sqrt[0.5]} + 0.5*(p1 + p2), {0.5*Sqrt[0.5], 0.5*Sqrt[0.5]} + 0.5*(p1 + p2)}], Line[{{-0.5*Sqrt[0.5], 0.5*Sqrt[0.5]} + 0.5*(p1 + p2), {0.5*Sqrt[0.5], -0.5*Sqrt[0.5]} + 0.5*(p1 + p2)}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])} + {-0.1, -0.7}, {1, 0}]}, ImageSize -> {45, 45}]]
          );
        labelbotnf[x_] := Grid[{{Style[textosarestas[[x]], FontFamily -> "Courier New"], Button[(
              p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
              p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
              p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {-0.5, 0.75}*Norm[p2 - p1];
              r1 = p1 - {0.5*Norm[p2 - p1], 0};
              r2 = p2 + {0.5*Norm[p2 - p1], 0};
              If[pesoarestas[[x]] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}]}, ImageSize -> {15, 15}], If[pesoarestas[[x]] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}]}, ImageSize -> {15, 15}], "??"]]),
             (
              Which[apertoubotnf[[x, 1]] == fechado, (apertoubotnf[[x, 1]] = aberto; apertoubotnf[[x, 2]] = frame), True, Null];
              )], Style[StringReplace[textosarestas[[x]], _ -> " "], FontFamily -> "Courier New"]}}];
        labelbotna[x_] := Grid[{{Style[textosarestas[[x]], FontFamily -> "Courier New"], Button[(
              p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
              p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
              p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {-0.5, 0.75}*Norm[p2 - p1];
              r1 = p1 - {0.5*Norm[p2 - p1], 0};
              r2 = p2 + {0.5*Norm[p2 - p1], 0};
              If[pesoarestas[[x]] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}]}, ImageSize -> {15, 15}], If[pesoarestas[[x]] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}]}, ImageSize -> {15, 15}], "??"]]),
             (
              Which[apertoubotna[[x, 1]] == aberto, (apertoubotna[[x, 1]] = fechado; apertoubotna[[x, 2]] = frame), True, Null];
              )], Style[StringReplace[textosarestas[[x]], _ -> " "], FontFamily -> "Courier New"]}}];
        labelchave[x_] := Button["interrupt" <> ToString@pesoarestas[[x]], (
           pesoarestas[[x]] = If[pesoarestas[[x]] == aberto, fechado, aberto];
           )];
        labeltempon[x_] := (
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          r1 = p1 - {0.5*Norm[p2 - p1], 0};
          r2 = p2 + {0.5*Norm[p2 - p1], 0};
          p3 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {-0.5, -0.25}*Norm[p2 - p1];
          p4 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.5, 0.25}*Norm[p2 - p1];
          p5 = {p1[[1]], Max[p1[[2]], p2[[2]]]} + {-0.25, -0.25}*Norm[p2 - p1];
          ligado = (potencial[arestas[[x, 1]]] == "F1" && potencial[arestas[[x, 2]]] == "F2") || (potencial[arestas[[x, 1]]] == "F2" && potencial[arestas[[x, 2]]] == "F1");
          Which[(ligado == True && histtemp[[x, 1]] != "ligado"), (histtemp[[x, 1]] = "ligado"; histtemp[[x, 2]] = frame;),
           (ligado == False && histtemp[[x, 1]] != "desligado"), (histtemp[[x, 1]] = "desligado"; histtemp[[x, 2]] = frame;)];
          If[(ligado == True),
           Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], EdgeForm[Black], FaceForm[Red], Rectangle[p3, p4], Rectangle[p5, p4], Line[{p3, {p5[[1]], p4[[2]]}}], Line[{{p3[[1]], p4[[2]]}, p5}], Text[Style[textosarestas[[x]] <> ":\n" <> ToString@(frame - histtemp[[x, 2]]), LineSpacing -> {0, 10}], 0.5*(p1 + p2) + {0.4, -0.1}]}, ImageSize -> {45, 45}],
           Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], EdgeForm[Black], FaceForm[White], Rectangle[p3, p4], Rectangle[p5, p4], Line[{p3, {p5[[1]], p4[[2]]}}], Line[{{p3[[1]], p4[[2]]}, p5}], Text[Style[textosarestas[[x]] <> "\n(" <> ToString@(confarestas[[x, 4]]) <> ")", LineSpacing -> {0, 10}], 0.5*(p1 + p2) + {0.4, -0.1}]}, ImageSize -> {45, 45}]]
          );
        labelcontnatempon[x_] := (
          auxbobina = confarestas[[x, 3]];
          contnatempon[x] = If[histtemp[[  (tempon[auxbobina][[1]]), 1  ]] == "ligado" && (frame - histtemp[[  (tempon[auxbobina][[1]]), 2  ]]) >= (tempon[auxbobina][[2]]), fechado, aberto];
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {-0.5, 0.75}*Norm[p2 - p1];
          r1 = p1 - {0.5*Norm[p2 - p1], 0};
          r2 = p2 + {0.5*Norm[p2 - p1], 0};
          If[contnatempon[x] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])}, {1, 0}]}, ImageSize -> {30, 30}], If[contnatempon[x] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{p1, p2}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r2[[1]], 0.5*(r1[[2]] + r2[[2]])}, {1, 0}]}, ImageSize -> {45, 45}], "??"]]
          );
        labelcontnftempon[x_] := (
          auxbobina = confarestas[[x, 3]];
          contnftempon[x] = If[histtemp[[  (tempon[auxbobina][[1]]), 1  ]] == "ligado" && (frame - histtemp[[  (tempon[auxbobina][[1]]), 2  ]]) >= (tempon[auxbobina][[2]]), aberto, fechado];
          p1 = PropertyValue[{circ, arestas[[x, 1]]}, VertexCoordinates];
          p2 = PropertyValue[{circ, arestas[[x, 2]]}, VertexCoordinates];
          p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {-0.5, 0.75}*Norm[p2 - p1];
          r1 = p1 - {0.5*Norm[p2 - p1], 0};
          p3 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.35, 1.}*Norm[p2 - p1];
          p4 = {p1[[1]], Min[p1[[2]], p2[[2]]]} + {0.5, 0.9}*Norm[p2 - p1];
          r1 = p1 - {0.5*Norm[p2 - p1], 0};
          r2 = p2 + {0.5*Norm[p2 - p1], 0};
          If[contnftempon[x] == aberto, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p3}], Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p4}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r1[[1]], 0.5*(r1[[2]] + r2[[2]])}, {-1, 0}]}, ImageSize -> {30, 30}], If[contnftempon[x] == fechado, Graphics[{White, Rectangle[r1, r2], Black, Line[{{p1[[1]], Max[p1[[2]], p2[[2]]]}, p3}], Line[{{p1[[1]], Min[p1[[2]], p2[[2]]]}, p3}], Text[Style[textosarestas[[x]], FontFamily -> "Courier New"], {r1[[1]], 0.5*(r1[[2]] + r2[[2]])}, {-1, 0}]}, ImageSize -> {30, 30}], "??"]]
          );
        potencial[x_] := If[MemberQ[VertexList@caminho[verticeF1], x], "F1", If[MemberQ[VertexList@caminho[verticeF2], x], "F2",
           If[MemberQ[VertexList@caminho[verticeP1], x], "P1",
            If[MemberQ[VertexList@caminho[verticeP2], x], "P2",
             If[MemberQ[VertexList@caminho[verticeP3], x], "P3",
              "open"]]]]];
        (*animacarga3f[x_]:=(
        If[Sort[{potencial[  x[[4,1]] ],potencial[  x[[4,2]] ],potencial[  x[[4,3]] ]}]=={"P1","P2","P3"},
        Graphics[{EdgeForm[Black],FaceForm[Red],Disk[{0,0},1],Text[Style[x[[3]],Bold],{0,0},{0,0}]}],Graphics[{EdgeForm[Black],FaceForm[White],Disk[{0,0},1],Text[Style[x[[3]],Bold],{0,0},{0,0}]}]]
        );*)
        (*animacarga3f[x_]:=(
        If[Sort[{potencial[  x[[4,1]] ],potencial[  x[[4,2]] ],potencial[  x[[4,3]] ]}]=={"P1","P2","P3"}
        ,Graphics[{EdgeForm[Black],FaceForm[Red],Disk[{0,0},1],Text[Style[x[[3]],Bold],{0,0},{0,0}]}]
        ,If[Sort[{potencial[  x[[4,1]] ],potencial[  x[[4,2]] ],potencial[  x[[4,3]] ]}]=={"open","open","open"}
        ,Graphics[{EdgeForm[Black],FaceForm[White],Disk[{0,0},1],Text[Style[x[[3]],Bold],{0,0},{0,0}]}]
        ,Graphics[{EdgeForm[Black],FaceForm[Lighter[Purple,0.5]],Disk[{0,0},1],Text[Style[x[[3]],Bold],{0,0},{0,0}]}]]]
        );*)
        animacarga3f[x_] := (
          If[Sort[{potencial[  x[[4, 1]] ], potencial[  x[[4, 2]] ], potencial[  x[[4, 3]] ]}] == {"P1", "P2", "P3"}
           , Graphics[{Transparent, Rectangle[{-5, -15}, {5, -3}], Opacity[1], EdgeForm[Black], FaceForm[Red], Rectangle[{-7, -12}, {7, -8}], Line[{{-5, -8}, {-5, -6.3}}], Line[{{0, -8}, {0, -6.3}}], Line[{{5, -8}, {5, -6.3}}], Text[Style[x[[3]], Bold], {0, -10}, {0, 0}]}]
           , If[Sort[{potencial[  x[[4, 1]] ], potencial[  x[[4, 2]] ], potencial[  x[[4, 3]] ]}] == {"open", "open", "open"}
            , Graphics[{Transparent, Rectangle[{-5, -15}, {5, -3}], Opacity[1], EdgeForm[Black], FaceForm[White], Rectangle[{-7, -12}, {7, -8}], Line[{{-5, -8}, {-5, -6.3}}], Line[{{0, -8}, {0, -6.3}}], Line[{{5, -8}, {5, -6.3}}], Text[Style[x[[3]], Bold], {0, -10}, {0, 0}]}]
            , Graphics[{Transparent, Rectangle[{-5, -15}, {5, -3}], Opacity[1], EdgeForm[Black], FaceForm[Lighter[Purple, 0.7]], Rectangle[{-7, -12}, {7, -8}], Line[{{-5, -8}, {-5, -6.3}}], Line[{{0, -8}, {0, -6.3}}], Line[{{5, -8}, {5, -6.3}}], Text[Style[x[[3]], Bold], {0, -10}, {0, 0}]}]]]
          );
        fechado = 0.001; aberto = 1000; bobina = 500;
        tiposbobinas = {"bobcont", "tempon", "lamp"};
        
        arestasbobcont = Position[confarestas, "bobcont"][[;; , 1]];
        arestastempon = Position[confarestas, "tempon"][[;; , 1]];
        arestassensterm = Position[confarestas, "contnasensterm"][[;; , 1]];
        apertoubotna = Table[{aberto, Null}, {n, 1, Length@confarestas}];
        apertoubotnf = Table[{fechado, Null}, {n, 1, Length@confarestas}];
        resetterm = Table[0, {n, 1, Length@confarestas}];
        Do[(bobcont[confarestas[[arestasbobcont[[x]], 3]]] = confarestas[[arestasbobcont[[x]], 1]]), {x, 1, Length@arestasbobcont}];
        Do[(tempon[confarestas[[arestastempon[[x]], 3]]] = {arestastempon[[x]], confarestas[[arestastempon[[x]], 4]]}), {x, 1, Length@arestastempon}];
        Do[(termico[confarestas[[arestassensterm[[x]], 3]]] = x), {x, 1, Length@arestassensterm}];
        histtemp = Table[{"-", Null}, {n, 1, Length@confarestas}];
        numframesbobna = 1;
        numframesbobnf = 1;
        vertices = confvertices[[;; , 1]];
        posvertices = confvertices[[;; , 2]];
        auxarestas = confarestas[[;; , 1]];
        arestas = {};
        For[cont = 1, cont <= Length@auxarestas, cont++, (
          arestas = Append[arestas, auxarestas[[cont, 1]] <-> auxarestas[[cont, 2]]];
          )];
        labelarestas = Table[Null, {cont, 1, Length@arestas}];
        tiposarestas = confarestas[[;; , 2]];
        textosarestas = Table["-", {n, 1, Length@confarestas}];
        Do[(
          Which[Length[confarestas[[cont]]] >= 3, textosarestas[[cont]] = confarestas[[cont, 3]]];
          ), {cont, 1, Length@textosarestas}];
        figurasvertices = Table[Null, {cont, 1, Length@cargas}];
        tamanhovertices = Table[Null, {cont, 1, Length@cargas}];
        (*tamfigura=9*{80,80};*)
        tamfigura = {1100, 750}(*tamanho*)(*20.{Max@confvertices[[;;,2,1]],Max@confvertices[[;;,2,2]]}*);
        guardaimagens = Table[Null, {n, 1, 2*200000}];
        gerafig = False;
        mostralabelvertices = False;
        ), AnimationRate -> 0.6, AnimationRunning -> True, LocalizeVariables -> False, DisplayAllSteps -> True, TrackedSymbols :> {pesoarestas, apertoubotna, apertoubotnf, resetterm, frame, gerafig, circ, mostralabelvertices}];
    Dynamic@Grid[{{Deploy@operacaoedicao}, {Switch[run, False, Deploy@edita, True, Deploy@opera]}}, ItemSize -> {Automatic, {Automatic, Automatic}}, Frame -> True, Spacings -> 0]
    ), LocalizeVariables -> False],1800, Alignment -> Center]

...

Assymmetric short-circuit calculation, with Marina Paollilo

Symmetrical components: Unbalanced three-phase circuit may be converted to three sets of balanced phasors.

0: Zero sequence system ((Subscript[(OverDot[V]), A])=(Subscript[(OverDot[V]), B])=(Subscript[(OverDot[V]), C]))

1: Positive sequence system ((Subscript[(OverDot[V]), B])=(1∠-120°)(Subscript[(OverDot[V]), A]) ;  (Subscript[(OverDot[V]), C])=(1∠120°)(Subscript[(OverDot[V]), A]))

2: Negative sequence system ((Subscript[(OverDot[V]), B])=(1∠120°)(Subscript[(OverDot[V]), A]) ;  (Subscript[(OverDot[V]), C])=(1∠-120°)(Subscript[(OverDot[V]), A]))

Pane[Manipulate[(
a=Exp[I*2*Pi/3];

(*a = -1./2.+I*Sqrt[3]/2;*)
(*aquad = -1/2-I*Sqrt[3]/2;*)

T = {{1,1,1},{1,a^2,a},{1,a,a^2}};

p=300.;

Va =pA[[1.]]+I*pA[[2]];
Vb =pB[[1]]+I*pB[[2]];
Vc =pC[[1]]+I*pC[[2]];

{{V0},{V1},{V2}}=Inverse[T].{{Va},{Vb},{Vc}};
TableForm[{{V0},{V1},{V2}}];

p1Va = Re[Va];
p2Va = Im[Va];
p1Vb = Re[Vb];
p2Vb = Im[Vb];
p1Vc = Re[Vc];
p2Vc = Im[Vc];
p1V0 = Re[V0];
p2V0 = Im[V0];

p1V1 = Re[V1];
p2V1 = Im[V1];
V1b=Abs[V1]* Exp[I*(Arg[V1]-((2Pi)/3))];
p1V1b = Re[V1b];
p2V1b = Im[V1b];
V1c=Abs[V1]* Exp[I*(Arg[V1]+2*Pi/3)];
p1V1c = Re[V1c];
p2V1c = Im[V1c];
p1V2 = Re[V2];
p2V2 = Im[V2];
V2b=Abs[V2]* Exp[I*(Arg[V2]+2*Pi/3)];
p1V2b = Re[V2b];
p2V2b = Im[V2b];
V2c=Abs[V2]* Exp[I*(Arg[V2]-2*Pi/3)];
p1V2c = Re[V2c];
p2V2c = Im[V2c];

(*If[p1Va ≥ p1Vb, (If[p1Va≥p1Vc,p0=p1Va,p0=p1Vc]),(If[p1Vb≥p1Vc,p0=p1Vb,p0=p1Vc])
];*)

Graphics[
{Opacity[0.1],FontFamily->"Courier New",Rectangle[{-p-200,-p-600},{1000+7*p,p+200}],Opacity[1],
(*Va,Vb,Vc*),Thickness[0.003],
Red,Arrowheads[0.015], Arrow[{{0,0},pA}],
Blue,Arrow[{{0,0},pB}],
Darker[Green,0.3],Arrow[{{0,0},pC}],
(*=*)
Black,Line[{{p+100,10},{p+130,10}}],
Black,Line[{{p+100,-10},{p+130,-10}}],
(*V0*)
Red,Arrow[{{2*p+230,0},{p1V0+2*p+230,p2V0}}],
Blue, Arrow[{{2*p+230,30},{p1V0+2*p+230,p2V0+30}}],
Darker[Green,0.3],Arrow[{{2*p+230,-30},{p1V0+2*p+230,p2V0-30}}],
(*+*)
Black,Line[{{3*p+330,0},{3*p+360,0}}],
Black,Line[{{3*p+345,15},{3*p+345,-15}}],
(*V1*)
Red,Arrow[{{4*p+460,0},{p1V1+4*p+460,p2V1}}],
Blue, Arrow[{{4*p+460,0},{p1V1b+4*p+460,p2V1b}}],
Darker[Green,0.3],Arrow[{{4*p+460,0},{p1V1c+4*p+460,p2V1c}}],
(*+*)
Black,Line[{{5*p+560,0},{5*p+590,0}}],
Black,Line[{{5*p+575,15},{5*p+575,-15}}],
(*V2*)
Red,Arrow[{{6*p+660,0},{p1V2+6*p+660,p2V2}}],
Blue,Arrow[{{6*p+660,0},{p1V2b+6*p+660,p2V2b}}],
Darker[Green,0.3],Arrow[{{6*p+660,0},{p1V2c+6*p+660,p2V2c}}],

Red,FontSize->24, Text["Va",{pA[[1]],If[pA[[2]]<0,pA[[2]]-50,pA[[2]]+50]}],
Blue,Text["Vb",{pB[[1]],If[pB[[2]]<0,pB[[2]]-50,pB[[2]]+50]}],
Darker[Green,0.3],Text["Vc",{pC[[1]],If[pC[[2]]<0,pC[[2]]-50,pC[[2]]+50]}],

Red,FontSize->20, Text["V0a",{If[p1V0 <0, p1V0+2*p+190,p1V0+2*p+280 ],p2V0}],
Blue,Text["V0b",{If[p1V0 <0, p1V0+2*p+190,p1V0+2*p+280 ],p2V0+50}],
Darker[Green,0.3],Text["V0c",{If[p1V0 <0, p1V0+2*p+190,p1V0+2*p+280 ],p2V0-50}],


Red,FontSize->24, Text["V1a",{p1V1+4*p+460,If[p2V1<0,p2V1-50,p2V1+50]}],
Blue, Text["V1b",{p1V1b+4*p+460,If[p2V1b<0,p2V1b-50,p2V1b+50]}],
Darker[Green,0.3], Text["V1c",{p1V1c+4*p+460,If[p2V1c<0,p2V1c-50,p2V1c+50]}],

Red,FontSize->24, Text["V2a",{p1V2+6*p+660,If[p2V2<0,p2V2-50,p2V2+50]}],
Blue, Text["V2b",{p1V2b+6*p+660,If[p2V2b<0,p2V2b-50,p2V2b+50]}],
Darker[Green,0.3], Text["V2c",{p1V2c+6*p+660,If[p2V2c<0,p2V2c-50,p2V2c+50]}],

Vatexto = StringJoin["Va = ",ToString[PaddedForm[Abs[Va],{5,2}]]," ∠ ",If[Arg[Va]<0.,"-"," "],ToString[PaddedForm[Abs@Arg[Va]/Pi*180,{5,2}]],"° V"];
Vbtexto = StringJoin["Vb = ",ToString[PaddedForm[Abs[Vb],{5,2}]]," ∠ ",If[Arg[Vb]<0.,"-"," "],ToString[PaddedForm[Abs@Arg[Vb]/Pi*180,{6,2}]],"° V"];
Vctexto = StringJoin["Vc = ",ToString[PaddedForm[Abs[Vc],{5,2}]]," ∠ ",If[Arg[Vc]<0.,"-"," "],ToString[PaddedForm[Abs@Arg[Vc]/Pi*180,{6,2}]],"° V"];

V0texto = StringJoin["V0 = ",ToString[PaddedForm[Abs[V0],{5,2}]]," ∠ ",If[Arg[V0]<0.,"-"," "],ToString[PaddedForm[Abs@Arg[V0]/Pi*180,{5,2}]],"° V"];
V1texto = StringJoin["V1 = ",ToString[PaddedForm[Abs[V1],{5,2}]]," ∠ ",If[Arg[V1]<0.,"-"," "],ToString[PaddedForm[Abs@Arg[V1]/Pi*180,{6,2}]],"° V"];
V2texto = StringJoin["V2 = ",ToString[PaddedForm[Abs[V2],{5,2}]]," ∠ ",If[Arg[V2]<0.,"-"," "],ToString[PaddedForm[Abs@Arg[V2]/Pi*180,{6,2}]],"° V"];

Black,FontWeight->Bold, Text["\!\(\*SubscriptBox[OverscriptBox[\(V\), \(.\)], \(\(0\)\(\\ \)\)]\)",{2*p+230,p+120}],
Black,FontWeight->Bold, Text["\!\(\*SubscriptBox[OverscriptBox[\(V\), \(.\)], \(\(1\)\(\\ \)\)]\)",{4*p+460,p+120}],
Black,FontWeight->Bold, Text["\!\(\*SubscriptBox[OverscriptBox[\(V\), \(.\)], \(\(2\)\(\\ \)\)]\)",{6*p+660,p+120}],



Black,FontWeight->Bold,Text[ Grid[ {{Vatexto,V0texto},{Vbtexto,V1texto},{Vctexto,V2texto}},Frame->All,Alignment->{{Left,Left}}],{10.2p,-2.9p},{1,-1}]



},ImageSize->2.3*{500,200}]
),
{{pA,{p,0.}},{-p,-p},{p,p},Locator} ,{{pB,{0.9p,-p}},{-p,-p},{p,p},Locator}, {{pC,{0.9p,p}},{-p,-p},{p,p},Locator},TrackedSymbols:>{pA,pB,pC}
],1500,Alignment->"Center"]

Assymmetric short-circuit calculation (continued)

Direct calculation of assymetric faults may involve large matrices with complex elements, particularly because of magnetic coupling between condutors and, moreover, different three phase connections of transformers

Assymmetric short-circuit calculation (continued)

Short circuit calculation may be carried out using equivalent single-phase circuits with appropriated connections. CDF file distributed to students

ClearAll["Global`*"];

PosLabel[p1_,comprimento_,angrot_,distancia_: 0.05,OptionsPattern[]]:=(Options[PosLabel]={ajustex->0,ajustey->0};
Module[{ajx,ajy,meio,coordtexto},ajx=OptionValue[ajustex];
ajy=OptionValue[ajustey];
meio=p1+comprimento/2*{-Sin[angrot],Cos[angrot]};
coordtexto=Switch[angrot,Pi/2,meio+{0,distancia*comprimento},-Pi/2,meio+{0,-distancia*comprimento},_,meio+{distancia*comprimento/Cos[angrot],0}]+{ajx,ajy}])

FonteCA[p1_,p2o_,texto_,OptionsPattern[]]:=(Options[FonteCA]={ocupacao->0.25,distlabel->0.4,estilotexto->"None",ajustelabelx->0,ajustelabely->0,alinhamento->{0,0}};
Module[{k9,distancia,estilo,ajustelabelx2,ajustelabely2,comprimento,angrot,p2,termfonte1,termfonte2,centrofonte,raiofonte,c1,c2,centroarcosenoide1,centroarcosenoide2,teta,corpofonte,imfonte,alinha},k9=OptionValue[ocupacao];
distancia=OptionValue[distlabel];
estilo=OptionValue[estilotexto];
ajustelabelx2=OptionValue[ajustelabelx];
ajustelabely2=OptionValue[ajustelabely];
alinha=OptionValue[alinhamento];
comprimento=((p2o[[2]]-p1[[2]])^2+(p2o[[1]]-p1[[1]])^2)^0.5;
angrot=Arg[p2o[[1]]-p1[[1]]+I*(p2o[[2]]-p1[[2]])]-Pi/2;
p2={p1[[1]],p1[[2]]+comprimento};
termfonte1={p1,p1+(0.5-k9/2)*(p2-p1)};
termfonte2={p1+(0.5+k9/2)*(p2-p1),p2};
centrofonte=(p1+p2)/2;
raiofonte=k9/2*comprimento;
c1=0.3;c2=0.1;
centroarcosenoide1=centrofonte+raiofonte*{c1,c2};
centroarcosenoide2=centrofonte-raiofonte*{c1,c2};(*para fazer a senoide*)raioarcosenoide=raiofonte*Sqrt[c1^2+c2^2];
teta=ArcCos[raiofonte*c2/raioarcosenoide];(*para fazer a senoide*)corpofonte=GraphicsGroup[{Circle[centrofonte,raiofonte],Circle[centroarcosenoide1,raioarcosenoide,{3*Pi/2-teta,3*Pi/2+teta}],Circle[centroarcosenoide2,raioarcosenoide,{Pi/2-teta,Pi/2+teta}]}];
imfonte=GraphicsGroup[{Line[termfonte1],corpofonte,Line[termfonte2]}];
imfonte=GeometricTransformation[imfonte,RotationTransform[angrot,p1]];
imfonte={imfonte,Text[Style[texto,estilo],PosLabel[p1,comprimento,angrot,distancia,ajustex->ajustelabelx2,ajustey->ajustelabely2],alinha]}]);
FonteCA::usage="[coordenada_inicial,coordenada_final,label,opcionais(ocupacao->0.25,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

Impedancia[p1_,p2o_,texto_,OptionsPattern[]]:=(Options[Impedancia]={ocupacao->0.6,proporcao->0.3,distlabel->0.4,estilotexto->"None",ajustelabelx->0,ajustelabely->0,alinhamento->{0,0}};
Module[{k7,k8,distancia,estilo,ajustelabelx2,ajustelabely2,comprimento,angrot,p2,termimp1,termimp2,corpoimp1,corpoimp2,corpoimp3,corpoimp4,imimp,alinha},k7=OptionValue[ocupacao];
k8=OptionValue[proporcao];
distancia=OptionValue[distlabel];
estilo=OptionValue[estilotexto];
ajustelabelx2=OptionValue[ajustelabelx];
ajustelabely2=OptionValue[ajustelabely];
alinha=OptionValue[alinhamento];
comprimento=((p2o[[2]]-p1[[2]])^2+(p2o[[1]]-p1[[1]])^2)^0.5;
angrot=Arg[p2o[[1]]-p1[[1]]+I*(p2o[[2]]-p1[[2]])]-Pi/2;
p2={p1[[1]],p1[[2]]+comprimento};
termimp1={p1,p1+(0.5-k7/2)*(p2-p1)};
termimp2={p1+(0.5+k7/2)*(p2-p1),p2};
corpoimp1={p1+(0.5-k7/2)*(p2-p1)-{k8*comprimento*k7/2,0},p1+(0.5-k7/2)*(p2-p1)+{k8*comprimento*k7/2,0}};
corpoimp2={p1+(0.5+k7/2)*(p2-p1)-{k8*comprimento*k7/2,0},p1+(0.5+k7/2)*(p2-p1)+{k8*comprimento*k7/2,0}};
corpoimp3={p1+(0.5-k7/2)*(p2-p1)-{k8*comprimento*k7/2,0},p1+(0.5+k7/2)*(p2-p1)-{k8*comprimento*k7/2,0}};
corpoimp4={p1+(0.5-k7/2)*(p2-p1)+{k8*comprimento*k7/2,0},p1+(0.5+k7/2)*(p2-p1)+{k8*comprimento*k7/2,0}};
imimp=GraphicsGroup[{Line[termimp1],Line[corpoimp1],Line[corpoimp2],Line[corpoimp3],Line[corpoimp4],Line[termimp2]}];
imimp=GeometricTransformation[imimp,RotationTransform[angrot,p1]];
imimp={imimp,Text[Style[texto,estilo],PosLabel[p1,comprimento,angrot,distancia,ajustex->ajustelabelx2,ajustey->ajustelabely2],alinha]}]);
Impedancia::usage="[coordenada_inicial,coordenada_final,label,opcionais(ocupacao->0.6,proporcao->0.3,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

ArcoTensao[p1_,p2o_,texto_,OptionsPattern[]]:=(Options[ArcoTensao]={sentido->"hor",proporcao->0.15,proporcaoseta->1,distlabel->0.4,estilotexto->"None",ajustelabelx->0,ajustelabely->0};
Module[{sentidox,k1,proporcaosetax,distancia,estilo,ajustelabelx2,ajustelabely2,comprimento,h,angrot,p2,larg,r,teta,centro,cabecaseta,imarco},sentidox=OptionValue[sentido];
k1=OptionValue[proporcao];
proporcaosetax=OptionValue[proporcaoseta];
distancia=OptionValue[distlabel];
estilo=OptionValue[estilotexto];
ajustelabelx2=OptionValue[ajustelabelx];
ajustelabely2=OptionValue[ajustelabely];
comprimento=((p2o[[2]]-p1[[2]])^2+(p2o[[1]]-p1[[1]])^2)^0.5;
h=((p2o[[2]]-p1[[2]])^2+(p2o[[1]]-p1[[1]])^2)^0.5;
angrot=Arg[(p2o[[1]]-p1[[1]])+I (p2o[[2]]-p1[[2]])]-π/2;
p2={p1[[1]],p1[[2]]+h};larg=k1*h;
r=(h^2/4+larg^2)/(2 larg);teta=ArcSin[h/(2 r)];
centro={p1[[1]]+If[sentidox=="hor",r Cos[teta],-r Cos[teta]],p1[[2]]+r Sin[teta]};
cabecaseta=GeometricTransformation[Line[{{p2[[1]]-0.03*proporcaosetax*h,p2[[2]]-0.1*proporcaosetax*h},p2,{p2[[1]]+0.03*proporcaosetax*h,p2[[2]]-0.1*proporcaosetax*h}}],RotationTransform[If[sentidox=="hor",-teta,teta],p2]];
imarco={Circle[centro,r,If[sentidox=="hor",{teta+π,-teta+π},{-teta,teta}]],cabecaseta};
imarco=GeometricTransformation[imarco,RotationTransform[angrot,p1]];
imarco={imarco,Text[Style[texto,estilo],PosLabel[p1,comprimento,angrot,distancia,ajustex->ajustelabelx2,ajustey->ajustelabely2]]}]);
ArcoTensao::usage="[coordenada_inicial,coordenada_final,label,optionais(sentido->\"hor\"(aspas duplas),proporcao->0.15,proporcaoseta->1,distlabel->0.4, estilo->\"None\",ajustelabelx  ->0,ajustelabely->0)]";

SetaCorrente[p1_,p2o_,texto_,OptionsPattern[]]:=(Options[SetaCorrente]={propcomeco->0.1,compseta->0.1,distseta->0.04,proporcaoseta->3,distlabel->0.4,estilotexto->"None",ajustelabelx->0,ajustelabely->0};
Module[{propcomecox,compsetax,dist,propseta,distancia,estilo,ajustelabelx2,ajustelabely2,comprimento,angrot,p2,p1x,p2x,imseta,r,p1xx},propcomecox=OptionValue[propcomeco];
compsetax=OptionValue[compseta];
dist=OptionValue[distseta];
propseta=OptionValue[proporcaoseta];
distancia=OptionValue[distlabel];
estilo=OptionValue[estilotexto];
ajustelabelx2=OptionValue[ajustelabelx];
ajustelabely2=OptionValue[ajustelabely];
comprimento=((p2o[[2]]-p1[[2]])^2+(p2o[[1]]-p1[[1]])^2)^0.5;
angrot=Arg[p2o[[1]]-p1[[1]]+I*(p2o[[2]]-p1[[2]])]-Pi/2;
p2={p1[[1]],p1[[2]]+comprimento};
p1x=p1+{-dist*comprimento,propcomecox*comprimento};
p2x=p1x+{0,compsetax*comprimento};
imseta={Line[{p1x,p2x}],Line[{p2x+propseta*{-0.03*compsetax*comprimento,-0.1*compsetax*comprimento},p2x,p2x+propseta*{0.03*compsetax*comprimento,-0.1*compsetax*comprimento}}]};
imseta=GeometricTransformation[imseta,RotationTransform[angrot,p1]];
r=RotationTransform[angrot,p1];
p1xx=r[p1x];
imseta={imseta,Text[Style[texto,estilo],PosLabel[p1xx,compsetax*comprimento,angrot,distancia,ajustex->ajustelabelx2,ajustey->ajustelabely2]]}]);
SetaCorrente::usage="[coordenada_inicial,coordenada_final,label,opcionais(propcomeco-> 0.1,compseta ->0.1,distseta->0.04,proporcaoseta->3,distlabel->0.4,estilo->\"None\",ajustelabelx->0,ajustelabely->0)]";

paralelo[x_]:=(soma=0;
If[Length[x]==0,("Argumento deve estar entre chaves{}"),If[MemberQ[N[x],0.]==True,0,(For[c=1,c≤Length[x],c++,(soma=soma+1/x[[c]])];
If[soma==0,Infinity,soma=1/soma])]]);
paraleloThevenin[x_]:=(Module[{corr,zeq},If[MemberQ[N[x[[;;,2]]],0.]==True,corr=0,corr=Total[x[[;;,1]]/x[[;;,2]]]];
zeq=paralelo[x[[;;,2]]];
saida={If[zeq==Infinity,0,corr*zeq],zeq}]);

formatar[x_,digdec_: 2]:=If[digdec==0,(If[x==I,"j",If[x==-I,"-j",If[Im[x]==0,(NumberForm[Round[N[x]],0]),If[Re[x]==0&&Im[x]>0,Row[{"j",NumberForm[Round[Im[x]],0]}],If[Re[x]==0&&Im[x]<0,Row[{"-j",NumberForm[Round[Abs[Im[x]]],0]}],Row[{NumberForm[Round[Re[x]],0],If[Sign[Im[x]]≥0,"+j","-j"],NumberForm[Round[Abs[Im[x]]],0]}]]]]]]),(If[x==I,"j",If[x==-I,"-j",If[Im[x]==0,(NumberForm[N[x],{10,digdec}]),If[Re[x]==0&&Im[x]>0,Row[{"j",NumberForm[Im[x],{10,digdec}]}],If[Re[x]==0&&Im[x]<0,Row[{"-j",NumberForm[Abs[Im[x]],{10,digdec}]}],Row[{NumberForm[Re[x],{10,digdec}],If[Sign[Im[x]]≥0,"+j","-j"],NumberForm[Abs[Im[x]],{10,digdec}]}]]]]]])]

polar[x_,digabs_:2,digangle_:1]:=Row[{formatar[Abs[x],digabs]," ∠ ",formatar[Arg[x]/Pi*180,digangle],"°"}]

alfa=Exp[I*2*Pi/3];
T={{1,1,1},{1,alfa^2,alfa},{1,alfa,alfa^2}};
k=1;


zgA0=I*0.5;

zgA2=I*0.5;
zTR1=I*0.1;
z1TR1=I*0.1;
z2TR1=I*0.1;

zL10=0.06+I*0.15;
zL20=0.06+I*0.15;
zL11=0.02+I*0.05;
zL21=0.02+I*0.05;
zL12=0.02+I*0.05;
zL22=0.02+I*0.05;
zTR2=0;
z1TR2=0;
z2TR2=0;

zgB0=I*0.83333;

zgB1=I*0.33333;

zgB2=I*0.33333;

zgA1=I*0.5;
zgB1=I*0.3;

zgA2=zgA1;
zgB2=zgB1;

zgA0=zgA1;
zgB0=I*0.8;

zTR1=I*0.1;
z1TR1=I*0.1;
z2TR1=I*0.1;

zTR2=I*0.08;
z1TR2=I*0.08;
z2TR2=I*0.08;

faseterra=Pane[Manipulate[(

vgA0=absvgA0*Exp[I*argvgA0/180.*Pi];
absvgB0=absvgA0;
argvgB0=argvgA0;
vgB0=absvgB0*Exp[I*argvgB0/180.*Pi];

absvgB1=absvgA1;
absvgB2=absvgA2;



Which[
Trafo1Lig=="Δ-Y"&&!AterramentoSTR1,(Trafo1="Δ-Y";AterramentoPTR1=False),
Trafo1Lig=="Δ-Y"&&AterramentoSTR1,(Trafo1="Δ-Yat";AterramentoPTR1=False),
Trafo1Lig=="Y-Δ"&&!AterramentoPTR1,(Trafo1="Y-Δ";AterramentoSTR1=False),
Trafo1Lig=="Y-Δ"&&AterramentoPTR1,(Trafo1="Yat-Δ";AterramentoSTR1=False;argvgB1=argvgA1-30.;argvgB2=argvgA2+30.),
Trafo1Lig=="Y-Y"&&!AterramentoPTR1&&!AterramentoSTR1,(Trafo1="Y-Y"),
Trafo1Lig=="Y-Y"&&AterramentoPTR1&&!AterramentoSTR1,(Trafo1="Yat-Y"),
Trafo1Lig=="Y-Y"&&!AterramentoPTR1&&AterramentoSTR1,(Trafo1="Y-Yat"),
Trafo1Lig=="Y-Y"&&AterramentoPTR1&&AterramentoSTR1,(Trafo1="Yat-Yat"),
Trafo1Lig=="Δ-Δ",(Trafo1="Δ-Δ";AterramentoPTR1=False;AterramentoSTR1=False)
];

Which[
Trafo2Lig=="Δ-Y"&&!AterramentoSTR2,(Trafo2="Δ-Y";AterramentoPTR2=False),
Trafo2Lig=="Δ-Y"&&AterramentoSTR2,(Trafo2="Δ-Yat";AterramentoPTR2=False),
Trafo2Lig=="Y-Δ"&&!AterramentoPTR2,(Trafo2="Y-Δ";AterramentoSTR2=False),
Trafo2Lig=="Y-Δ"&&AterramentoPTR2,(Trafo2="Yat-Δ";AterramentoSTR2=False),
Trafo2Lig=="Y-Y"&&!AterramentoPTR2&&!AterramentoSTR2,Trafo2="Y-Y",
Trafo2Lig=="Y-Y"&&AterramentoPTR2&&!AterramentoSTR2,Trafo2="Yat-Y",
Trafo2Lig=="Y-Y"&&!AterramentoPTR2&&AterramentoSTR2,Trafo2="Y-Yat",
Trafo2Lig=="Y-Y"&&AterramentoPTR2&&AterramentoSTR2,Trafo2="Yat-Yat",
Trafo2Lig=="Δ-Δ",(Trafo2="Δ-Δ";AterramentoPTR2=False;AterramentoSTR2=False)
];

gerA=Translate[#,{-20,0}]&/@{FonteCA[{-6,15},{-6,22},Style[Subscript[Overscript["v","."],"GA"],{FontSize->16}],ajustelabelx->-5.2],Line[{{-6,22},{0,22}}],Line[{{-6,15},{0,15}}]};
gerB=Translate[#,{-20,0}]&/@{FonteCA[{34,15},{34,22},Style[Subscript[Overscript["v","."],"GB"],{FontSize->16}]],Line[{{28,22},{34,22}}],Line[{{28,15},{34,15}}]};
transformador=Translate[#,{-20,0}]&/@{Circle[{3.65,22},1],Circle[{3.65+0.7,22},1],Line[{{0,22},{2.65,22}}],Line[{{5.35,22},{8,22}}],Line[{{0,15},{8,15}}],Text[Style["TR1",{FontSize->12}],{4,24}],Text[Style[Trafo1,{FontSize->12}],{4,19.5}]};
transformador2=Translate[#,{-20,0}]&/@{Circle[{3.65,22},1],Circle[{3.65+0.7,22},1],Line[{{0,22},{2.65,22}}],Line[{{5.35,22},{8,22}}],Line[{{0,15},{8,15}}],Text[Style["TR2",{FontSize->12}],{4,24}],Text[Style[Trafo2,{FontSize->12}],{4,19.5}]};
barras=Translate[#,{-20,0}]&/@{Line[{{0,22-0.5},{0,22+0.5}}]};
lt=Translate[#,{-20,0}]&/@{Line[{{8,22},{14,22}}],Text[Style["LT1",{FontSize->12}],{11.2,23}],Line[{{14,22},{20,22}}],Text[Style["LT2",{FontSize->12}],{17.2,23}],Line[{{8,15},{20,15}}]};
lt0=Translate[#,{-20,0}]&/@{Impedancia[{8,7},{14,7},Style[Subscript["z","0","LT1"],{FontSize->14}],ocupacao->0.4,ajustelabely->3.5],Impedancia[{14,7},{20,7},Style[Subscript["z","0","LT2"],{FontSize->14}],ocupacao->0.4,ajustelabely->3.5],Line[{{8,0},{20,0}}]};
lt1=Translate[#,{-20,0}]&/@{Impedancia[{8,7},{14,7},Style[Subscript["z","1","LT1"],{FontSize->14}],ocupacao->0.4,ajustelabely->3.5],Impedancia[{14,7},{20,7},Style[Subscript["z","1","LT2"],{FontSize->14}],ocupacao->0.4,ajustelabely->3.5],Line[{{8,0},{20,0}}]};
lt2=Translate[#,{-20,0}]&/@{Impedancia[{8,7},{14,7},Style[Subscript["z","2","LT1"],{FontSize->14}],ocupacao->0.4,ajustelabely->3.5],Impedancia[{14,7},{20,7},Style[Subscript["z","2","LT2"],{FontSize->14}],ocupacao->0.4,ajustelabely->3.5],Line[{{8,0},{20,0}}]};

k1=If[Trafo1=="Δ-Yat",1,If[Trafo1=="Δ-Y",2,If[Trafo1=="Yat-Δ",3,If[Trafo1=="Y-Δ",4,If[Trafo1=="Yat-Yat",5,If[Trafo1=="Yat-Y",6,If[Trafo1=="Y-Yat",7,If[Trafo1=="Y-Y",8,If[Trafo1=="Δ-Δ",9,0]]]]]]]]];
k2=If[Trafo2=="Δ-Yat",1,If[Trafo2=="Δ-Y",2,If[Trafo2=="Yat-Δ",3,If[Trafo2=="Y-Δ",4,If[Trafo2=="Yat-Yat",5,If[Trafo2=="Yat-Y",6,If[Trafo2=="Y-Yat",7,If[Trafo2=="Y-Y",8,If[Trafo2=="Δ-Δ",9,0]]]]]]]]];
transf10diagrama=Table[{},{n,1,9}];
transf10diagrama[[1]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{4,0},{4,7},Style[Subscript["3Z","at(S)"],{FontSize->14}],ocupacao->0.4,ajustelabelx->0.3],Impedancia[{4,7},{8,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.8]};
transf10diagrama[[2]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{4,7},{8,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.8]};
transf10diagrama[[3]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{4,0},{4,7},Style[Subscript["3Z","at(P)"],{FontSize->14}],ocupacao->0.4,ajustelabelx->0.3],Impedancia[{0,7},{4,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.8]};
transf10diagrama[[4]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{4,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.8]};
transf10diagrama[[5]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{8/3,7},Style[Subscript["3Z","at(P)"],{FontSize->10}],ajustelabely->-0.3,ajustelabelx->-0.1],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR1"],{FontSize->10}],ajustelabely->2],Impedancia[{16/3,7},{8,7},Style[Subscript["3Z","at(S)"],{FontSize->10}],ajustelabely->-0.3,ajustelabelx->0.1]};
transf10diagrama[[6]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{8/3,7},Style[Subscript["3Z","at(P)"],{FontSize->10}],ajustelabely->-0.3,ajustelabelx->-0.1],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR1"],{FontSize->10}],ajustelabely->2]};
transf10diagrama[[7]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR1"],{FontSize->10}],ajustelabely->2],Impedancia[{16/3,7},{8,7},Style[Subscript["3Z","at(S)"],{FontSize->10}],ajustelabely->-0.3,ajustelabelx->0.1]};
transf10diagrama[[8]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR1"],{FontSize->10}],ajustelabely->2]};
transf10diagrama[[9]]={Line[{{-20,0},{-12,0}}]};
transf11diagrama=Table[{},{n,1,9}];
transf11diagrama[[1]]={Line[{{0-20,0},{8-20,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["+30°",{11}],{5.5-20,3.5}]};
transf11diagrama[[2]]=transf11diagrama[[1]];
transf11diagrama[[3]]={Line[{{0-20,0},{8-20,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["-30°",{11}],{5.5-20,3.5}]};
transf11diagrama[[4]]=transf11diagrama[[3]];
transf11diagrama[[5]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{4,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.7],Line[{{4,7},{8,7}}]};
transf11diagrama[[6]]=transf11diagrama[[5]];
transf11diagrama[[7]]=transf11diagrama[[5]];
transf11diagrama[[8]]=transf11diagrama[[5]];
transf11diagrama[[9]]=transf11diagrama[[5]];
transf12diagrama=Table[{},{n,1,9}];
transf12diagrama[[1]]={Line[{{0-20,0},{8,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["-30°",{11}],{5.5-20,3.5}]};
transf12diagrama[[2]]=transf12diagrama[[1]];
transf12diagrama[[3]]={Line[{{0-20,0},{8-20,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["+30°",{11}],{5.5-20,3.5}]};
transf12diagrama[[4]]=transf12diagrama[[3]];
transf12diagrama[[5]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{4,7},Style[Subscript["z","TR1"],{FontSize->14}],ajustelabely->2.7],Line[{{4,7},{8,7}}]};
transf12diagrama[[6]]=transf12diagrama[[5]];
transf12diagrama[[7]]=transf12diagrama[[5]];
transf12diagrama[[8]]=transf12diagrama[[5]];
transf12diagrama[[9]]=transf12diagrama[[5]];
(*Transformador 2*)transf20diagrama=Table[{},{n,1,9}];
transf20diagrama[[1]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{4,0},{4,7},Style[Subscript["3Z","at(S)"],{FontSize->14}],ocupacao->0.4,ajustelabelx->0.3],Impedancia[{4,7},{8,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.8]};
transf20diagrama[[2]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{4,7},{8,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.8]};
transf20diagrama[[3]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{4,0},{4,7},Style[Subscript["3Z","at(P)"],{FontSize->14}],ocupacao->0.4,ajustelabelx->0.3],Impedancia[{0,7},{4,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.8]};
transf20diagrama[[4]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{4,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.8]};
transf20diagrama[[5]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{8/3,7},Style[Subscript["3Z","at(P)"],{FontSize->10}],ajustelabely->-0.3,ajustelabelx->-0.1],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR2"],{FontSize->10}],ajustelabely->2],Impedancia[{16/3,7},{8,7},Style[Subscript["3Z","at(S)"],{FontSize->10}],ajustelabely->-0.3,ajustelabelx->0.1]};
transf20diagrama[[6]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{8/3,7},Style[Subscript["3Z","at(P)"],{FontSize->10}],ajustelabelx->-0.1],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR2"],{FontSize->10}],ajustelabely->2]};
transf20diagrama[[7]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR2"],{FontSize->10}],ajustelabely->2],Impedancia[{16/3,7},{8,7},Style[Subscript["3Z","at(S)"],{FontSize->10}],ajustelabely->-0.1,ajustelabelx->0.1]};
transf20diagrama[[8]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{8/3,7},{16/3,7},Style[Subscript["z","TR2"],{FontSize->10}],ajustelabely->2]};
transf20diagrama[[9]]={Line[{{-20,0},{-12,0}}]};
transf21diagrama=Table[{},{n,1,9}];
transf21diagrama[[1]]={Line[{{0-20,0},{8-20,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["+30°",{11}],{5.5-20,3.5}]};
transf21diagrama[[2]]=transf21diagrama[[1]];
transf21diagrama[[3]]={Line[{{0-20,0},{8-20,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["-30°",{11}],{5.5-20,3.5}]};
transf21diagrama[[4]]=transf21diagrama[[3]];
transf21diagrama[[5]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{4,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.7],Line[{{4,7},{8,7}}]};
transf21diagrama[[6]]=transf21diagrama[[5]];
transf21diagrama[[7]]=transf21diagrama[[5]];
transf21diagrama[[8]]=transf21diagrama[[5]];
transf21diagrama[[9]]=transf21diagrama[[5]];
transf22diagrama=Table[{},{n,1,9}];
transf22diagrama[[1]]={Line[{{0-20,0},{8-20,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["-30°",{11}],{5.5-20,3.5}]};
transf22diagrama[[2]]=transf22diagrama[[1]];
transf22diagrama[[3]]={Line[{{0-20,0},{8-20,0}}],Impedancia[{0-20,7},{4-20,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.7],Line[{{4-20,7},{8-20,7}}],EdgeForm[Black],FaceForm[White],Polygon[{{4-20,7.5},{7-20,7.5},{7-20,-0.5},{4-20,-0.5}}],Text[Style["+30°",{11}],{5.5-20,3.5}]};
transf22diagrama[[4]]=transf22diagrama[[3]];
transf22diagrama[[5]]=Translate[#,{-20,0}]&/@{Line[{{0,0},{8,0}}],Impedancia[{0,7},{4,7},Style[Subscript["z","TR2"],{FontSize->14}],ajustelabely->2.7],Line[{{4,7},{8,7}}]};
transf22diagrama[[6]]=transf22diagrama[[5]];
transf22diagrama[[7]]=transf22diagrama[[5]];
transf22diagrama[[8]]=transf22diagrama[[5]];
transf22diagrama[[9]]=transf22diagrama[[5]];

legendas={FontSize->12,FontWeight->Bold,Text["Sistema\nTrifásico",{-20-20-1,18.5},{-1,0}],Text["Sequência\nZero",{-20-20-1,3.5},{-1,0}],Text["Sequência\nPositiva",{-20-20-1,-6.5},{-1,0}],Text["Sequência\nNegativa",{-20-20-1,-16.5},{-1,0}]};
legbarras=Translate[#,{-20,0}]&/@{Text["10",{0,23}],Text["20",{8,23}],Text["30",{14,23}],Text["40",{20,23}],Text["50",{28,23}]};
(*Curtos*)xb=-20+If[BarraCurto=="Barra10",0,If[BarraCurto=="Barra20",8,If[BarraCurto=="Barra30",14,If[BarraCurto=="Barra40",20,If[BarraCurto=="Barra50",28,0]]]]];
impfalta={Red,Line[{{40-20,-10},{40-20,-23}}],Switch[ImpedânciaFalta,0,Line[{{40-20,11},{40-20,-10}}],_,Impedancia[{40-20,11},{40-20,-10},Style[Subscript["3z","F"],{FontSize->14}],ocupacao->0.2,ajustelabelx->11.]]};
curtoft={Red,Line[{{xb,-3},{xb,0}}],Line[{{xb,-13},{xb,-10}}],Line[{{xb,-23},{xb,-20}}],Line[{{40-20,-23},{xb,-23}}],Line[{{40-20,11},{xb,11}}],Line[{{xb,11},{xb,7}}],Blue,Text[StringTake[BarraCurto,-2]<>"(0)",{xb,4.5}],Text[StringTake[BarraCurto,-2]<>"(1)",{xb,-4.5}],Text[StringTake[BarraCurto,-2]<>"(2)",{xb,-14.5}]};
setacurto={Red,SetaCorrente[{41-20,10},{41-20,3},Style[Subscript[Overscript["i","."],"0"],{FontSize->14}],compseta->0.6,distlabel->-0.3]};
curtoftfase={Red,Line[{{xb,15},{xb,16}}],Text[Style["Curto\nFase A\nterra",LineSpacing->{0,12}],{xb,18}],Line[{{xb,20},{xb,22}}]};
(*Cálculos*)

(*Transformador1*)If[Trafo1=="Δ-Yat",{ztAa=Infinity,ztAb=zTR1,ztAc=3*zatSTR1,defA1=30,defA2=-30},If[Trafo1=="Δ-Y",{ztAa=Infinity,ztAb=zTR1,ztAc=Infinity,defA1=30,defA2=-30},If[Trafo1=="Yat-Δ",{ztAa=zTR1,ztAb=Infinity,ztAc=3*zatPTR1,defA1=-30,defA2=30},If[Trafo1=="Y-Δ",{ztAa=zTR1,ztAb=Infinity,ztAc=Infinity,defA1=-30,defA2=30},If[Trafo1=="Yat-Yat",{ztAa=3*zatPTR1+zTR1,ztAb=3*zatSTR1,ztAc=Infinity,defA1=0,defA2=0},If[Trafo1=="Yat-Y",{ztAa=zTR1+3*zatPTR1,ztAb=Infinity,ztAc=Infinity,defA1=0,defA2=0},If[Trafo1=="Y-Yat",{ztAa=Infinity,ztAb=zTR1+3*zatSTR1,ztAc=Infinity,defA1=0,defA2=0},If[Trafo1=="Y-Y",{ztAa=Infinity,ztAb=Infinity,ztAc=Infinity,defA1=0,defA2=0},If[Trafo1=="Δ-Δ",{ztAa=Infinity,ztAb=Infinity,ztAc=Infinity,defA1=0,defA2=0},0]]]]]]]]];
vgA1=(absvgA1*Exp[I*argvgA1/180*Pi])*Exp[-30*I/180*Pi];
vgA2=(absvgA2*Exp[I*argvgA2/180*Pi])*Exp[30*I/180*Pi];
(*Transformador2*)If[Trafo2=="Δ-Yat",{ztBa=Infinity,ztBb=zTR2,ztBc=3*zatSTR2,defB1=30,defB2=-30},If[Trafo2=="Δ-Y",{ztBa=Infinity,ztBb=zTR2,ztBc=Infinity,defB1=30,defB2=-30},If[Trafo2=="Yat-Δ",{ztBa=zTR2,ztBb=Infinity,ztBc=3*zatPTR2,defB1=-30,defB2=30},If[Trafo2=="Y-Δ",{ztBa=zTR2,ztBb=Infinity,ztBc=Infinity,defB1=-30,defB2=30},If[Trafo2=="Yat-Yat",{ztBa=3*zatPTR2+zTR2,ztBb=3*zatSTR2,ztBc=Infinity,defB1=0,defB2=0},If[Trafo2=="Yat-Y",{ztBa=zTR2,ztBb=Infinity,ztBc=Infinity,defB1=0,defB2=0},If[Trafo2=="Y-Yat",{ztBa=Infinity,ztBb=zTR2,ztBc=Infinity,defB1=0,defB2=0},If[Trafo2=="Y-Y",{ztBa=Infinity,ztBb=Infinity,ztBc=Infinity,defB1=0,defB2=0},If[Trafo2=="Δ-Δ",{ztBa=Infinity,ztBb=Infinity,ztBc=Infinity,defB1=0,defB2=0},0]]]]]]]]];

(*argvgB1=argvgA1/Pi*180+defA1+defB1;
argvgB2=argvgA2+defA2+defB2;*)
vgB1=Chop@(absvgB1*Exp[I*(Arg@vgA1+(defA1+defB1)/180.*Pi)]);
vgB2=Chop@(absvgB2*Exp[I*(Arg@vgA2+(defA2+defB2)/180.*Pi)]);

gerA0=Translate[#,{-20,0}]&/@{Switch[Chop[absvgA0],0,Line[{{-6,0},{-6,7}}],_,FonteCA[{-6,0},{-6,7},Style[Column@{Row@{Abs@vgA0," p.u."},Row@{"∠",Arg@vgA0/Pi*180,"°"}},{FontSize->12}],ajustelabelx->-4,alinhamento->{1,0}]],Line[{{-6,0},{0,0}}],Impedancia[{-6,7},{0,7},Style[Subscript["z","0","GA"],{FontSize->14}],ocupacao->0.3,ajustelabely->3.5]};
gerA1=Translate[#,{-20,0}]&/@{Switch[Chop[absvgA1],0,Line[{{-6,0},{-6,7}}],_,FonteCA[{-6,0},{-6,7},Style[Column@{Row@{Abs@vgA1," p.u."},Row@{"∠",Arg@vgA1/Pi*180,"°"}},{FontSize->12}],ajustelabelx->-4,alinhamento->{1,0}]],Line[{{-6,0},{0,0}}],Impedancia[{-6,7},{0,7},Style[Subscript["z","1","GA"],{FontSize->14}],ocupacao->0.3,ajustelabely->3.5]};
gerA2=Translate[#,{-20,0}]&/@{Switch[Chop[absvgA2],0,Line[{{-6,0},{-6,7}}],_,FonteCA[{-6,0},{-6,7},Style[Column@{Row@{Abs@vgA2," p.u."},Row@{"∠",Arg@vgA2/Pi*180,"°"}},{FontSize->12}],ajustelabelx->-4,alinhamento->{1,0}]],Line[{{-6,0},{0,0}}],Impedancia[{-6,7},{0,7},Style[Subscript["z","2","GA"],{FontSize->14}],ocupacao->0.3,ajustelabely->3.5]};
gerB0=Translate[#,{-20,0}]&/@{Switch[Chop[absvgB0],0,Line[{{34,0},{34,7}}],_,FonteCA[{34,0},{34,7},Style[Column@{Row@{Abs@vgB0," p.u."},Row@{"∠",Arg@vgB0/Pi*180,"°"}},{FontSize->12}],ajustelabelx->-1.7,alinhamento->{-1,0}]],Impedancia[{28,7},{34,7},Style[Subscript["z","0","GB"],{FontSize->14}],ocupacao->0.3,ajustelabely->3.5],Line[{{28,0},{34,0}}]};
gerB1=Translate[#,{-20,0}]&/@{Switch[Chop[absvgB1],0,Line[{{34,0},{34,7}}],_,FonteCA[{34,0},{34,7},Style[Column@{Row@{Abs@vgB1," p.u."},Row@{"∠",Arg@vgB1/Pi*180,"°"}},{FontSize->12}],ajustelabelx->-1.7,alinhamento->{-1,0}]],Impedancia[{28,7},{34,7},Style[Subscript["z","1","GB"],{FontSize->14}],ocupacao->0.3,ajustelabely->3.5],Line[{{28,0},{34,0}}]};
gerB2=Translate[#,{-20,0}]&/@{Switch[Chop[absvgB2],0,Line[{{34,0},{34,7}}],_,FonteCA[{34,0},{34,7},Style[Column@{Row@{Abs@vgB2," p.u."},Row@{"∠",Arg@vgB2/Pi*180,"°"}},{FontSize->12}],ajustelabelx->-1.7,alinhamento->{-1,0}]],Impedancia[{28,7},{34,7},Style[Subscript["z","2","GB"],{FontSize->14}],ocupacao->0.3,ajustelabely->3.5],Line[{{28,0},{34,0}}]};

Th[10,"esq",0]={vgA0,zgA0};
Th[10,"dir",0]={0,ztAa}+paraleloThevenin[{{0,ztAc},{0,ztAb}+{0,zL10}+{0,zL20}+{0,ztBa}+paraleloThevenin[{{0,ztBc},{0,ztBb}+{vgB0,zgB0}}]}];
Th[10,0]=paraleloThevenin[{Th[10,"esq",0],Th[10,"dir",0]}];
Th[20,"esq",0]={0,ztAb}+paraleloThevenin[{{0,ztAc},{0,ztAa}+{vgA0,zgA0}}];
Th[20,"dir",0]={0,zL10}+{0,zL20}+{0,ztBa}+paraleloThevenin[{{0,ztBc},{0,ztBb}+{vgB0,zgB0}}];
Th[20,0]=paraleloThevenin[{Th[20,"dir",0],Th[20,"esq",0]}];
Th[30,"esq",0]={0,zL10}+{0,ztAb}+paraleloThevenin[{{0,ztAc},{0,ztAa}+{vgA0,zgA0}}];
Th[30,"dir",0]={0,zL20}+{0,ztBa}+paraleloThevenin[{{0,ztBc},{0,ztBb}+{vgB0,zgB0}}];
Th[30,0]=paraleloThevenin[{Th[30,"dir",0],Th[30,"esq",0]}];
Th[40,"esq",0]={0,zL20}+{0,zL10}+{0,ztAb}+paraleloThevenin[{{0,ztAc},{0,ztAa}+{vgA0,zgA0}}];
Th[40,"dir",0]={0,ztBa}+paraleloThevenin[{{0,ztBc},{0,ztBb}+{vgB0,zgB0}}];
Th[40,0]=paraleloThevenin[{Th[40,"dir",0],Th[40,"esq",0]}];
Th[50,"esq",0]={0,ztBb}+paraleloThevenin[{{0,ztBc},{0,ztBa}+{0,zL20}+{0,zL10}+{0,ztAb}+paraleloThevenin[{{0,ztAc},{0,ztAa}+{vgA0,zgA0}}]}];
Th[50,"dir",0]={vgB0,zgB0};
Th[50,0]=paraleloThevenin[{Th[50,"dir",0],Th[50,"esq",0]}];
Th[10,"esq",1]={vgA1,zgA1};
Th[10,"dir",1]={0,z1TR1}+{0,zL11}+{0,zL21}+{0,z1TR2}+{vgB1*Exp[(-defB1-defA1)*I*Pi/180],zgB1};
Th[10,1]=paraleloThevenin[{Th[10,"dir",1],Th[10,"esq",1]}];
Th[20,"esq",1]={0,z1TR1}+{vgA1*Exp[defA1*I*Pi/180],zgA1};
Th[20,"dir",1]={0,zL11}+{0,zL21}+{0,z1TR2}+{vgB1*Exp[(-defB1)*I*Pi/180],zgB1};
Th[20,1]=paraleloThevenin[{Th[20,"dir",1],Th[20,"esq",1]}];
Th[30,"esq",1]={0,z1TR1}+{0,zL11}+{vgA1*Exp[defA1*I*Pi/180],zgA1};
Th[30,"dir",1]={0,zL21}+{0,z1TR2}+{vgB1*Exp[(-defB1)*I*Pi/180],zgB1};
Th[30,1]=paraleloThevenin[{Th[30,"dir",1],Th[30,"esq",1]}];
Th[40,"esq",1]={0,z1TR1}+{0,zL11}+{0,zL21}+{vgA1*Exp[defA1*I*Pi/180],zgA1};
Th[40,"dir",1]={0,z1TR2}+{vgB1*Exp[(-defB1)*I*Pi/180],zgB1};
Th[40,1]=paraleloThevenin[{Th[40,"dir",1],Th[40,"esq",1]}];
Th[50,"esq",1]={0,z1TR1}+{0,zL11}+{0,zL21}+{0,z1TR2}+{vgA1*Exp[(defA1+defB1)*I*Pi/180],zgA1};
Th[50,"dir",1]={vgB1,zgB1};
Th[50,1]=paraleloThevenin[{Th[50,"dir",1],Th[50,"esq",1]}];
Th[10,"esq",2]={vgA2,zgA2};
Th[10,"dir",2]={0,z2TR1}+{0,zL12}+{0,zL22}+{0,z2TR2}+{vgB2*Exp[(-defB2-defA2)*I*Pi/180],zgB2};
Th[10,2]=paraleloThevenin[{Th[10,"dir",2],Th[10,"esq",2]}];
Th[20,"esq",2]={0,z2TR1}+{vgA2*Exp[defA2*I*Pi/180],zgA2};
Th[20,"dir",2]={0,zL12}+{0,zL22}+{0,z2TR2}+{vgB2*Exp[(-defB2)*I*Pi/180],zgB2};
Th[20,2]=paraleloThevenin[{Th[20,"dir",2],Th[20,"esq",2]}];
Th[30,"esq",2]={0,z2TR1}+{0,zL12}+{vgA2*Exp[defA2*I*Pi/180],zgA2};
Th[30,"dir",2]={0,zL22}+{0,z2TR2}+{vgB2*Exp[(-defB2)*I*Pi/180],zgB2};
Th[30,2]=paraleloThevenin[{Th[30,"dir",2],Th[30,"esq",2]}];
Th[40,"esq",2]={0,z2TR1}+{0,zL12}+{0,zL22}+{vgA2*Exp[defA2*I*Pi/180],zgA2};
Th[40,"dir",2]={0,z2TR2}+{vgB2*Exp[(-defB2)*I*Pi/180],zgB2};
Th[40,2]=paraleloThevenin[{Th[40,"dir",2],Th[40,"esq",2]}];
Th[50,"esq",2]={0,z2TR1}+{0,zL12}+{0,zL22}+{0,z2TR2}+{vgA2*Exp[(defA2+defB2)*I*Pi/180],zgA2};
Th[50,"dir",2]={vgB2,zgB2};
Th[50,2]=paraleloThevenin[{Th[50,"dir",2],Th[50,"esq",2]}];
If[BarraCurto=="Barra10",Th[Total]=Th[10,0]+Th[10,1]+Th[10,2]+{0,3*ImpedânciaFalta},If[BarraCurto=="Barra20",Th[Total]=Th[20,0]+Th[20,1]+Th[20,2]+{0,3*ImpedânciaFalta},If[BarraCurto=="Barra30",Th[Total]=Th[30,0]+Th[30,1]+Th[30,2]+{0,3*ImpedânciaFalta},If[BarraCurto=="Barra40",Th[Total]=Th[40,0]+Th[40,1]+Th[40,2]+{0,3*ImpedânciaFalta},If[BarraCurto=="Barra50",Th[Total]=Th[50,0]+Th[50,1]+Th[50,2]+{0,3*ImpedânciaFalta},0]]]]];
Ifalta=Th[Total][[1]]/Th[Total][[2]];
{{Ia},{Ib},{Ic}}=T.{{Ifalta},{Ifalta},{Ifalta}};
Ia=Chop[Ia];
Ib=Chop[Ib];
Ic=Chop[Ic];
Ifalta=Chop[Ifalta];
Ifalta=SetPrecision[Ifalta,3];
Ia=SetPrecision[Ia,3];
Ib=SetPrecision[Ib,3];
Ic=SetPrecision[Ic,3];
I0texto=Row[{Subscript[Overscript["i","."],"0"]," = ",ToString[Abs[Ifalta],TraditionalForm]," ∠ ",ToString[Arg[Ifalta]/Pi*180],"°"," p.u."}];
I1texto=Row[{Subscript[Overscript["i","."],"1"]," = ",ToString[Abs[Ifalta],TraditionalForm]," ∠ ",ToString[Arg[Ifalta]/Pi*180],"°"," p.u."}];
I2texto=Row[{Subscript[Overscript["i","."],"2"]," = ",ToString[Abs[Ifalta],TraditionalForm]," ∠ ",ToString[Arg[Ifalta]/Pi*180],"°"," p.u."}];
IAtexto=Row[{Subscript[Overscript["i","."],"A"]," = ",ToString[Abs[Ia],TraditionalForm]," ∠ ",ToString[Arg[Ia]/Pi*180],"°"," p.u."}];
IBtexto=Row[{Subscript[Overscript["i","."],"B"]," = ",ToString[Abs[Ib],TraditionalForm]," ∠ ",ToString[Arg[Ib]/Pi*180],"°"," p.u."}];
ICtexto=Row[{Subscript[Overscript["i","."],"C"]," = ",ToString[Abs[Ic],TraditionalForm]," ∠ ",ToString[Arg[Ic]/Pi*180],"°"," p.u."}];

circThev={Text[Style["Equivalentes de Thevenin:",{Bold,FontSize->12}],{42,23.5}],
Switch[Chop[Th[ToExpression@StringTake[BarraCurto,-2],2][[1]]],0,Line[{{32,-4},{32,0}}],_,FonteCA[{32,-4},{32,0},Row[{polar[Chop[Th[ToExpression@StringTake[BarraCurto,-2],2][[1]]],6,2]," p.u."}],ocupacao->0.5,alinhamento->{-1,0}]],Impedancia[{32,0},{32,4},Row[{formatar[Chop[Th[ToExpression@StringTake[BarraCurto,-2],2][[2]]],6]," p.u."}],alinhamento->{-1,0}]
,Switch[Chop[Th[ToExpression@StringTake[BarraCurto,-2],1][[1]]],0,Line[{{32,4},{32,8}}],_,FonteCA[{32,4},{32,8},Row[{polar[Chop[Th[ToExpression@StringTake[BarraCurto,-2],1][[1]]],6,2]," p.u."}],ocupacao->0.5,alinhamento->{-1,0}]],Impedancia[{32,8},{32,12},Row[{formatar[Chop[Th[ToExpression@StringTake[BarraCurto,-2],1][[2]]],6]," p.u."}],alinhamento->{-1,0}]
,Switch[Chop[Th[ToExpression@StringTake[BarraCurto,-2],0][[1]]],0,Line[{{32,12},{32,16}}],_,FonteCA[{32,12},{32,16},Row[{polar[Chop[Th[ToExpression@StringTake[BarraCurto,-2],0][[1]]],6,2]," p.u."}],ocupacao->0.5,alinhamento->{-1,0}]],Impedancia[{32,16},{32,20},Row[{formatar[Chop[Th[ToExpression@StringTake[BarraCurto,-2],0][[2]]],6]," p.u."}],alinhamento->{-1,0}]
,Blue,Line[{{31.5,4},{32.5,4}}],Text[Style[StringTake[BarraCurto,-2]<>" (2)"],{31.4,4},{1,0}]
,Line[{{31.5,12},{32.5,12}}],Text[Style[StringTake[BarraCurto,-2]<>" (1)"],{31.4,12},{1,0}]
,Line[{{31.5,20},{32.5,20}}],Text[Style[StringTake[BarraCurto,-2]<>" (0)"],{31.4,20},{1,0}]
,Red,Line[{{32,20},{32,22},{52,22}}],Switch[ImpedânciaFalta,0,Line[{{52,22},{52,-6}}],_,Impedancia[{52,22},{52,-6},Row[{3*ImpedânciaFalta," p.u."}],ocupacao->0.1,ajustelabelx->12,alinhamento->{-1,0}]],Line[{{52,-6},{32,-6},{32,-4}}],SetaCorrente[{53,18},{53,14},Subscript
[Overscript["i","."],"0"],compseta->0.6,ajustelabelx->2.3]
};

autoria={Text[Style[Row[{"Autoras:   ",Column@{"Marina Midori Nishimi Paolillo","Milana Lima dos Santos"}},Frame->True],{Italic,FontSize->8}],{-42,-25},{-1,-1}]};

Graphics[{{Opacity[0],Rectangle[{-42,25},{58,-25}]},gerA,transformador,barras,lt,lt0,Translate[lt1,{0,-10}],Translate[lt2,{0,-20}]
,Blue,Translate[barras,{{8,0},{14,0},{20,0},{28,0}
,{0,-15},{8,-15},{14,-15},{20,-15},{28,-15}
,{0,-25},{8,-25},{14,-25},{20,-25},{28,-25}
,{0,-35},{8,-35},{14,-35},{20,-35},{28,-35}}]
,Black,Translate[transformador2,{20,0}],gerB,gerA0,Translate[gerA1,{0,-10}],Translate[gerA2,{0,-20}],gerB0,Translate[gerB1,{0,-10}],Translate[gerB2,{0,-20}],transf10diagrama[[k1]],Translate[transf20diagrama[[k2]],{20,0}],Translate[transf11diagrama[[k1]],{0,-10}],Translate[transf21diagrama[[k2]],{20,-10}],Translate[transf12diagrama[[k1]],{0,-20}],Translate[transf22diagrama[[k2]],{20,-20}],curtoft,curtoftfase,legendas,Blue,legbarras,Black,impfalta,setacurto,{Black,FontWeight->Bold,FontSize->11,Text[Grid[{{"Resultados:",SpanFromLeft},{I0texto,IAtexto},{I1texto,IBtexto},{I2texto,ICtexto}},Frame->All,Spacings->{1.5,1.5},Alignment->{{Left,Left},ItemSize->All}],{22,-7.5},{-1,1}]},circThev,autoria},ImageSize->0.7{1150,573},PlotRange->{{-42,58},{-25,25}},ImageMargins->0,PlotRangeClipping->True]),
Row[{
Column[{Row@{Column[{Style["Curto Fase A - Terra",{FontWeight->Bold,FontSize->14,TextAlignment->Center,FontColor->Red}]
,Style["Obs.: Sistema operando em vazio "<>
"antes do curto",{Italic}]}]
,Spacer[180],Grid[{{"Local do curto:",Control@{{BarraCurto,"Barra10",""},{"Barra10","Barra20","Barra30","Barra40","Barra50"}}},{Row[{"impedância da falta ( "Subscript["z","F"]," )"}],Row[{Control@{{ImpedânciaFalta,0,""},{0,0.25}}," p.u."}]}},Alignment->{Left,Center},Spacings->{0,0.1}]},
Row[{
Grid[{
{Subscript["v","GA","0"],
Control@{{absvgA0,0,""},{0,0.2,1.0}}," p.u.",Spacer[0],Row[{"∠ ",Subscript[Overscript["v","."],"GA","0"]}],Control@{{argvgA0,0 ,""},{-15,0,15}},"°"},
{Subscript["v","GA","1"],Control@{{absvgA1,1,""},{0,0.2,1}}," p.u.",Spacer[0],Column[{Row[{"∠ ",Subscript[Overscript["v","."],"GA","1"]}],"(linha)"}],Control@{{argvgA1,0 ,""},{-15,0,15}},"°"},
{Subscript["v","GA","2"],Control@{{absvgA2,0,""},{0,0.2,1.0}}," p.u.",Spacer[0],Column[{Row[{"∠ ",Subscript[Overscript["v","."],"GA","2"]}],"(linha)"}],Control@{{argvgA2,0 ,""},{-15,0,15}},"°"}},Frame->True,FrameStyle->Lighter[Gray,0.5],Spacings->{0,0.1},ItemSize->{1.1{3,5.5,2.35,1,4,6.5,0.9},3.1},Alignment->{{Right,Right,Left,Automatic,Right,Right,Left,Automatic},Center}],
Spacer[7],
Column[
{
Control@{{Trafo1Lig,"Δ-Y",Style[" TR1 ",{FontSize->12,Bold}]},{"Δ-Y","Y-Δ","Y-Y","Δ-Δ"}},
Row[{Control@{{AterramentoPTR1,False,"Terra (P)"},{False,True},Enabled->(Trafo1Lig=="Y-Δ"||Trafo1Lig=="Y-Y")},Spacer[10],
Control@{{AterramentoSTR1,False,"Terra (S)"},{False,True},Enabled->(Trafo1Lig=="Δ-Y"||Trafo1Lig=="Y-Y")}}],
Row[{Spacer[10],Subscript["z","at"],Column[{
Row[{Control@{{zatPTR1,0,""},{0,0.05,0.2},Enabled->(Trafo1Lig=="Y-Δ"||Trafo1Lig=="Y-Y")}," p.u. (P)"}],Row[{Control@{{zatSTR1,0,""},{0,0.05,0.2},Enabled->(Trafo1Lig=="Δ-Y"||Trafo1Lig=="Y-Y")}," p.u. (S)"}]
}]
}]}
,Frame->True,FrameStyle->Lighter[Gray,0.5],Spacings->{Automatic,0.5}]
,Spacer[7],
Column[
{
Control@{{Trafo2Lig,"Y-Δ",Style[" TR2 ",{FontSize->12,Bold}]},{"Δ-Y","Y-Δ","Y-Y","Δ-Δ"}},
Row[{Control@{{AterramentoPTR2,False,"Terra (P)"},{False,True},Enabled->(Trafo2Lig=="Y-Δ"||Trafo2Lig=="Y-Y")},Spacer[10],
Control@{{AterramentoSTR2,False,"Terra (S)"},{False,True},Enabled->(Trafo2Lig=="Δ-Y"||Trafo2Lig=="Y-Y")}}],
Row[{Spacer[10],Subscript["z","at"],Column[{
Row[{Control@{{zatPTR2,0,""},{0,0.05,0.2},Enabled->(Trafo2Lig=="Y-Δ"||Trafo2Lig=="Y-Y")}," p.u. (P)"}],Row[{Control@{{zatSTR2,0,""},{0,0.05,0.2},Enabled->(Trafo2Lig=="Δ-Y"||Trafo2Lig=="Y-Y")}," p.u. (S)"}]
}]
}]}
,Frame->True,FrameStyle->Lighter[Gray,0.5],Spacings->{Automatic,0.5}]
,Spacer[7]
,Grid[{{"Impedâncias das linhas, geradores e transformadores: ",SpanFromLeft,SpanFromLeft,SpanFromLeft,SpanFromLeft,SpanFromLeft,SpanFromLeft,SpanFromLeft,SpanFromLeft},
{Subscript["z","0","LT1"]," = ",Re@zL10,"+j",Im@zL10," p.u.",Spacer[1],Subscript["z","0","LT2"]," = ",Re@zL20,"+j",Im@zL20," p.u."},
{Subscript["z","1","LT1"]," = ",Re@zL11,"+j",Im@zL11," p.u.",Spacer[1],Subscript["z","1","LT2"]," = ",Re@zL21,"+j",Im@zL21," p.u."},
{Subscript["z","0","GA"]," = ","","+j",Im@zgA0," p.u.",Spacer[1],Subscript["z","0","GB"]," = ","","+j",Im@zgB0," p.u."},
{Subscript["z","1","GA"]," = ","","+j",Im@zgA1," p.u.",Spacer[1],Subscript["z","1","GB"]," = ","","+j",Im@zgB1," p.u."},
{Subscript["z","TR1"]," = ","","+j",Im@zTR1," p.u.",Spacer[1],Subscript["z","TR2"]," = ","","+j",Im@zTR2," p.u."}},Frame->True,FrameStyle->Lighter[Gray,0.5],Spacings->{0,0.1},ItemSize->{{3.5,1.5,3,1,3,2.7,1,2.8,1.5,3,1,3,2.7},1.5},Alignment->{{Center,Center,Right,Center,Left,Left,Center,Center,Center,Right,Center,Left,Left},Center}]
}]
}]
},Alignment->{Left,Top}],TrackedSymbols:>{BarraCurto,ImpedânciaFalta,Trafo1Lig,Trafo2Lig,AterramentoPTR1,AterramentoPTR2,AterramentoSTR1,AterramentoSTR2,absvgA0,argvgA0,absvgA1,argvgA1,absvgA2,argvgA2,zatPTR1,zatSTR1,zatPTR2,zatSTR2,ImpedânciaFalta},ImageMargins->0,SaveDefinitions->True],1500,Alignment->Center]

Impact of wind speed in the operation of wind turbines and generators (nb file ok, cdf file to be created)
By Fernando Nishida

Power generated increases with wind speed, up to nominal. AC/AC converter controls the rotating speed of the generator axis, so as to obtain maximum power;

In the range above nominal speed and below maximum speed, angle of the blades is adjusted to limit the mechanic power; above maximum wind speed the turbine is stopped to prevent damages.

Notebook was created using dynamic functions, except Manipulate. By clicking in each curve (P, cp, T) ou in “Nominal data”, more details are shown.

tffernando=Pane[DynamicModule[{beta,circ1,circ2,circ3,circeq,compantes,corfundo,cp,dadosdeplaca,digabs,digangle,digdec,disparagiro,display,esc,escolha,escolhatela,estilofonte,f,fig1,fig2,fig3,fig5,fig7,figflash,figwind,formatar,girando,giro,grafico,im,infotelamec,ir,is,k,lambda,lambdai,lambdamax,largura,linkdadosdeplaca,maismenosvel,margem,max,min,n,omega,omegas,omegat,p,Pag,passo,polar,potel,potele,prefixo,r,R,raio,rot,rotsincrono,rr,rs,s,saida,simb,simbcomp,slidervel,sufixo,t,TA,texto11,texto12,texto13,texto14,texto31,texto32,texto33,texto34,texto41,texto42,texto43,texto44,texto51,texto52,texto53,texto54,texto61,texto62,texto63,texto64,tm,tn,torqass,vm,vmax,vmin,vnom,vr,Vr,vrp,vrr,vs,vv,vvlim1,vvlim2,warn,x,xm,xr,xs,y,zeq},
(

(*-----------------Funcao Polar-----------------*)
formatar[y_,digdec_: 2,simb_: 0]:=(Module[{simbcomp,compantes,x},x=Chop[N[y]];
simbcomp=Switch[simb,0,"j",1,"i",2,"J",3,"I",4,"j",5,"i",6,"J",7,"I"];
compantes=Switch[simb,0,True,1,True,2,True,3,True,4,False,5,False,6,False,7,False];
ToString[If[digdec==0,NumberForm[N[Round[Re[x]]],0],NumberForm[N[Round[Re[x],10^(-digdec)]],{10,digdec}]]]<>If[Im[x]≠0,If[Im[x]>0,"+","-"]<>If[compantes==True,simbcomp,""]<>ToString[If[digdec==0,NumberForm[N[Round[Abs[Im[x]]]],0],NumberForm[N[Round[Abs[Im[x]],10^(-digdec)]],{10,digdec}]]],""]<>If[compantes==False,simbcomp,""]]);

polar[x_,digabs_: 2,digangle_: 1]:=ToString[formatar[Abs[x],digabs]]<>" ∠ "<>ToString[formatar[Arg[x]/Pi*180,digangle]]<>"°";

(*-----------------Valores Iniciais -----------------*)
(*Interface Mecânica*)
esc=1; (* escolha da tela a ser exibida em tamanho maior *)
escolha=1;  (* 1 = Tela com Slider; 2 = Tela com botões *)
(* Valores relativos ao modelo de turbina utilizado*)
vv=12.;r=7.5;
lambda=8.;
vvlim1=4;
vnom=13;
vvlim2=25;

omega=Dynamic@If[vv<3.5,0,
If[vv>3.5&&vv<14,1,
If[vv>14&&vv<25,2,
3
]]];

beta=Dynamic@If[vv<3.5,0,
If[vv>3.5&&vv<14,1,
If[vv>14&&vv<25,2,
3
]]];

vmin=0.;vmax=30.;

corfundo=Dynamic@If[vv<vvlim1,Yellow,If[vv<vvlim2,Green,Lighter[Red,0.4]]];

(*-----------------Help -----------------*)

texto11="Abaixo da velocidade de cut-in não há rotação das pás";
texto12="Mantém-se β=0° para se obter o máximo coeficiente de potência ((Subscript[C, p])) possível";
texto13="Produção de energia no valor nominal";
texto14="Acima da velocidade de cut-out (25m/s) não há produção de energia";
texto51="Pode-se definir uma (Subscript[Z, equivalente]) para o comportamento do conversor";
texto52="Abaixo da velocidade síncrona ocorre um fluxo de potência da rede para o conversor";
texto53="Acima da velocidade síncrona esse fluxo de potência se inverte";
texto54="Deve-se notar que a potência emitida para a rede é sempre a mesma";
texto31="β é o ângulo de giro da pá - máximo de 90°, ou seja estol total";
texto32="Nesta região velocidade de vento, o controle do conversor altera a tensão no rotor";
texto33="Acima de velocidade de vento nominal, o controle da turbina mantém a rotação do gerador no valor nominal";
texto34="Acima da velocidade de cut-out, o controle de estol assume fazendo o fluxo de vento escoar pela pá";
texto61="A curva em azul é a típica da máquina de indução e a em laranja com o efeito do DFIG";
texto62="Nesta faixa de velocidade o conversor altera a tensão no rotor e assim altera o torque";
texto63="Nesta faixa de velocidade o controle da turbina mantém a rotação nominal no gerador";
texto64="????";
texto41="Pela definição, Cp é razão entre a potência de saída e a potência do vento";
texto42="Cp é função de β e λ ângulo de passo da turbina e razão de velocidade de ponta de pá, respectivamente";
texto43="Acima de velocidade de vento nominal, o β é alterado para proteger e manter a integridade mecânica da turbina";
texto44="Acima da velocidade de cut-out não faz sentido o conceito de cp uma vez que o controle de estol para a turbina";


infotelamec=Dynamic@Text[Style[InsertLinebreaks[
Which[esc==1&&vv≤4,texto11,
esc==1&&vv>4&&vv<13,texto12,
esc==1&&vv>=13&&vv<=25,texto13,
esc==1&&vv>25,texto14,

(*Tela circuito*)
esc==5&&vv≤4,texto51,
esc==5&&vv>4&&vv<12.3,texto52,
esc==5&&vv>12.3&&vv<=25,texto53,
esc==5&&vv>25,texto54,

(*Tela torque*)
esc==6&&vv≤4,texto61,
esc==6&&vv>3&&vv<=13,texto62,
esc==6&&vv>13&&vv<=25,texto63,
esc==6&&vv>25,texto64,

(*tela potencia*)
esc==3&&vv≤4,texto31,
esc==3&&vv>4&&vv<=13,texto32,
esc==3&&vv>13&&vv<=25,texto33,
esc==3&&vv>25,texto34,

(*tela cp*)
esc==4&&vv≤4,texto41,
esc==4&&vv>4&&vv<=13,texto42,
esc==4&&vv>13&&vv<=25,texto43,
esc==4&&vv>25,texto44,
True," "
],50],{FontFamily->"Courier New",FontSize->12,TextAlignment->Left,Background->White}]];

(*-----------------Controle Mecanico-----------------*)

cp[beta_,lambda_]:=(
lambdai=((lambda*beta^3+lambda+0.08*beta^4+0.08*beta)/(beta^3+1-0.035*lambda+0.0028*beta));
0.34*(90/lambdai-0.5*beta-2.39)*E^(-29/lambdai) +0.0011*lambda
);

raio=45;

beta=Dynamic@If[vv<3,0,
If[vv>3&&vv<=13,
0
,
If[vv>13&&vv<25,
Round[2*vv-24],
90
]]];

omegat=Dynamic@If[vv<=4,0,
If[vv>4&&vv<=5,11.1882*vv/raio,
If[vv>5&&vv<12,0.02046*vv+1.140827 ,
If[vv>=12&&vv<=25,
1.559656,
0
]]]];

lambdamax=Dynamic@FindArgMax[cp[Setting@beta,lambda],{lambda,0.0001,15}][[1]];
(*-----------------Valores Iniciais Eletrico-----------------*)

omegas=2*Pi*50;
rotsincrono=1500;
rr=2.63/1000;
rs=2.65/1000;
xs=0.1687/1000*omegas;
xr=0.1337/1000*omegas;
xm=5.4749/1000*omegas;
vs=660; 
R=45; (*raio rotor*)
k=112.8;(*relação gearbox*)
tn=11368.1578;(*torque nominal*)
p=2; (*pares de pólos*)

(*-------------------------------------------------------Controle Eletrico----------------------------------------------------------*)


torqass[vr_,rot_]:=(Module[{s},
s=((1500-rot)/1500);

ir=If[s==0,0,((vs/Sqrt[3]-vr/s)/(rs+rr/s+I*(xs+xr)))];
Pag=Abs[ir]^2*rr/s+Re[vr*Conjugate[ir]/s]-Abs[ir]^2*rr;
TA=Pag/((1-s)*omegas/p)

]);

(*n em rpm - gerador*)
n=Dynamic[Setting@omegat*k*60/(2*Pi)];

vr[n_]:=(
s=((rotsincrono-n)/rotsincrono);
tm=-tn*(n/1150)^2;
is=(vs-Sqrt[vs^2-4*rs*tm*omegas/p])/(2*rs);
vm=vs-is*(rs+I*xs);
im=vm/(I*xm);
ir=is-im;
Vr=s*vm-ir*(rr+I*s*xr)
);

potel[n_]:=(
s=((rotsincrono-n)/rotsincrono);
tm=-tn*(n/rotsincrono)^2;
2*Pi*n/60*tm
);

vrr=Dynamic@vr[Setting@n];
zeq=Dynamic[Setting@vrr*Conjugate[Setting@ir]/(ir*Conjugate[Setting@ir])];
vrp=Dynamic@polar[Setting@vrr];
potele=Dynamic@potel[Setting@n];
(*-------------------------------------------------------Gráficos Mecanico----------------------------------------------------------*)

(*-----------------Graficos Turbina-----------------*)
grafico=Graphics[GraphicsGroup[{{AbsoluteThickness[1.6],StrokeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[None],Circle[{-0.14425240875200962,0.20786740424865302},{0.03364985766743539,0.033649857667435557}]},{AbsoluteThickness[1.6],StrokeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[None],Circle[{-0.14425240875200968,-0.020226897863226734},{0.048941798941799064,0.1944444444444443}]},{AbsoluteThickness[1.6],StrokeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[None],GeometricTransformation[Circle[{0.2923280423280424,0.5642507845619145},{0.04894179894179901,0.1944444444444443}],{{{{-0.5000000000000006,-0.8660254037844398},{0.8660254037844404,-0.5000000000000009}},{0.6926108121290073,0.3509136052731112}}}]},{AbsoluteThickness[1.6],StrokeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[None],GeometricTransformation[Circle[{0.2923280423280424,0.5642507845619145},{0.04894179894179901,0.1944444444444443}],{{{{-0.5000000000000009,0.8660254037844404},{-0.8660254037844404,-0.5000000000000009}},{-0.688787587304984,0.8572406270624272}}}]}}]];

(*-----------------Graficos de Valores-----------------*)

fig1=Dynamic@Graphics[{EdgeForm[Black],FaceForm[Setting@corfundo],Rectangle[{0,0},{10,10}],Black,Dynamic[If[esc==2,{FontWeight->Bold,FontSize->18},{FontSize->12}],TrackedSymbols:>{esc}],
Dynamic@Text["(Subscript[n, gerador]) = "<>ToString[Setting@n] <>" rpm",{0.3,0.+1.},{-1,0}],
Dynamic@Text["P = "<>ToString[Setting@potele,TraditionalForm] <>" W",{0.3,1*1.3+1.},{-1,0}],
Dynamic@Text["(Subscript[V, r]) = "<>ToString[Setting@vrp] <>" V",{0.3,2*1.3+1.},{-1,0}],
Dynamic@Text["(Subscript[X, eq])(conv) = "<>ToString[Im@Setting@zeq] <>" Ω",{0.3,3*1.3+1.},{-1,0}],
Dynamic@Text["(Subscript[R, eq])(conv) = "<>ToString[Re@Setting@zeq] <>" Ω",{0.3,4*1.3+1.},{-1,0}],
Dynamic@Text["β = "<>ToString[Setting@beta]<>" °",{0.3,5*1.3+1.},{-1,0}],
Dynamic@Text["C\!\(\*StyleBox[\"p\",FontSize->9]\) = "<>ToString[If[vv<20,Round[FindMaxValue[cp[Setting@beta,lambda],{lambda,0.0001,15}],0.01],"-"]],{0.3,6*1.3+1.},{-1,0}]},PlotRangePadding->0.1,PlotRangeClipping->True];

(*-----------------Graficos da Potencia-----------------*)

fig2=Dynamic@ListLinePlot[{{0,0},{3,0},{13,1},{15,1},{25,1},{25.01,0},{30,0}},
PlotLabel->None,LabelStyle->{GrayLevel[0],If[esc==3,FontSize->14,FontSize->6]},
Background->RGBColor[0.84`,0.92`,1.`],Ticks-> If[esc==3,{},{{20},{1}}],Epilog->{If[esc==3,FontSize->14,FontSize->8],Text["(Subscript[v, vento])(m/s)",{20,0.02},{1,-1}],Text["P[pu]",{0.6,1.},{-1,0.95}],If[esc==3,AbsolutePointSize[8],AbsolutePointSize[3]],Red,Point[{Setting@vv,If[vv<3,0,
If[vv>4&&vv<=13,
(vv-3)/10
,
If[vv>13&&vv<25,
1,
0
]]]}]}];

(*-----------------Graficos de aviso-----------------*)

warn=If [esc==4,,];

(*-----------------Grafico Cp-----------------*)

fig3=Dynamic@Plot[cp[Setting@beta,lambda],{lambda,0.05,15},(*AxesLabel->{"λ","C\!\(\*StyleBox[\"p\",FontSize->9]\)"},*)PlotLabel->None,LabelStyle->{GrayLevel[0],If[esc==4,FontSize->14,FontSize->6]},Background->RGBColor[0.84`,0.92`,1.`], PlotRange->{Automatic,{0,0.25}},Ticks->If[esc==4,{},{{14},{0.25}}],Epilog->{If[esc==4,FontSize->14,FontSize->8],Text["λ",{14,0.0},{0,-1}],Text["(Subscript[C, P])",{0.3,0.25},{-1,1}],If[esc==4,AbsolutePointSize[8],AbsolutePointSize[3]],Red,Point[{Setting@lambdamax,cp[Setting@beta,Setting@lambdamax]}],If[vv>20,Inset[warn,{7.5,0.125},{0.6626,0.5041},{15,0.25}]]}(*,Axes->False,Frame->{{True,False},{True,False}},FrameLabel->{{"C\!\(\*StyleBox[\"p\",FontSize->9]\)",None},{None,None}},FrameTicks->If[esc==4,{Automatic,Automatic},{{0,10},{0,{0.25,""}}}],*)];

(*-----------------Grafico Flash-----------------*)

figflash=Graphics[{GeometricTransformationBox[GraphicsGroupBox[{{EdgeForm[{RGBColor[0.,0.,0.],Opacity[1.],AbsoluteThickness[1.6]}],EdgeForm[None],FaceForm[RGBColor[1,1,0]],PolygonBox[{{0.2666666666666667,0.5055555555555555},{0.7000000000000002,0.5027777777777778},{1.1083333333333336`,0.9444444444444445}}]},{EdgeForm[{RGBColor[0.,0.,0.],Opacity[1.],AbsoluteThickness[1.6]}],EdgeForm[None],FaceForm[RGBColor[1,1,0]],PolygonBox[{{0.4944444444444446,0.5055555555555555},{0.9333333333333336,0.49722222222222223`},{0.1,0.06666666666666665}}]}}],{{{{0.6380024085503537,0.},{0.,0.5796430140158928}},{0.2812068781674945,0.20695825402529855`}}}],{AbsoluteThickness[1.6],StrokeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[{RGBColor[0.,0.,0.],Opacity[1.]}],EdgeForm[None],CircleBox[{0.6666666666666669,0.4951696415498672},{0.438888888888889,0.3861111111111112}]}}];

disparagiro=Row[{Checkbox[Dynamic[girando]],Style[" Exibe giro das pás",{FontFamily->"Arial"}]}];


(*----------------------------------------------------Gráficos Eletrico-------------------------------------------------------*)
circ1=;
circ2=;
circ3=;
circeq=;

(*fig5=Dynamic[Graphics[{EdgeForm[Black],FaceForm[Setting@corfundo],Rectangle[{0,0},{10,4}],Black,
Setting@Inset[If[vv<3,
If[esc==5,circ1,circ1]
,
If[vv>=3&&vv<12,
circ2,
If[vv≥12&&vv<20,
circ3,
circ1]]],{4.7,2.5},{0.66,0.3598391132357694`},ImageScaled@{1,0.5}]
,
PlotRangePadding->0,PlotRangeClipping->True}]];*)
fig5=Dynamic[
If[esc≠5,
Graphics[{EdgeForm[Black],FaceForm[Setting@corfundo],Rectangle[{0,0},{10,4}],Black,
Setting@Inset[If[vv<3,
If[esc==5,circ1,circ1]
,
If[vv>=3&&vv<12,
circ2,
If[vv≥12&&vv<20,
circ3,
circ1]]],{4.7,2.5},{0.66,0.3598391132357694`},ImageScaled@{1,0.5}],
PlotRangePadding->0,PlotRangeClipping->True}],
GraphicsColumn[{Graphics[{FaceForm[Setting@corfundo],Rectangle[{0,0},{10,4.2}],Black,
Inset[circeq,{5,1.9},{Center,Center},ImageScaled[{1,4.6}]],Black,Text["Circuito Equivalente",{5,3.6},{0,-1}]},
PlotRangePadding->0,PlotRangeClipping->True],
Graphics[{FaceForm[Setting@corfundo],Rectangle[{0,0},{10,4}],Black,
Setting@Inset[If[vv<3,
If[esc==5,circ1,circ1]
,
If[vv>=3&&vv<12,
circ2,
If[vv≥12&&vv<20,
circ3,
circ1]]],{4.7,2.5},{0.66,0.3598391132357694`},ImageScaled@{1,0.5}],Black,Text["Sistema turbina+DFIG+conversor",{5,3.0},{0,-1}]}
,
PlotRangePadding->0,PlotRangeClipping->True]},Background->Setting@corfundo,Spacings->0,Frame->True]]];

(*-----------------Grafico Torque-----------------*)

fig7=Dynamic@Plot[{torqass[0,f],torqass[Setting@vrr,f]},{f,1000,2000},PlotRange->{-6000,5000},
PlotLabel->None,LabelStyle->{GrayLevel[0]},
Background->RGBColor[0.84`,0.92`,1.`], PlotRange->{Automatic,{0,0.25}},Ticks->If[esc==6,{},{{},{}}],Epilog->{If[esc==6,FontSize->14,FontSize->8],Text["n",{1500,1},{0,-1}],Text["T",{505,5000},{-1,1}],If[esc==6,AbsolutePointSize[8],AbsolutePointSize[3]],Red,Point[{Setting@lambdamax,cp[Setting@beta,Setting@lambdamax]}],If[vv>20,Inset[warn,{7.5,0.125},{0.6626,0.5041},{15,0.25}]]}];

(*-----------------Grafico Vento-----------------*)

figwind=Graphics[{{EdgeForm[{GrayLevel[0.],Opacity[1.],AbsoluteThickness[1]}],EdgeForm[None],FaceForm[RGBColor[0,0.501961,1]],DiskBox[{0.04352367688022274,0.020862456818916852},{0.8842979257139961,0.884297925713996}]},GeometricTransformationBox[GraphicsGroupBox[{LineBox[{{-0.5774141132776233,-0.30052924791086366`},{-0.5774141132776233,-0.30052924791086433`}}],GraphicsGroupBox[{CircleBox[{0.704561281337047,0.713883472609099},{0.3012418755803157,0.286116527390901},NCache[{Rational[-1,2] Pi,Pi},{-1.5707963267948966`,3.141592653589793}]],LineBox[{{-0.5082985143918236,0.4277669452181976},{0.7045612813370474,0.4277669452181969}}]}],GeometricTransformationBox[GraphicsGroupBox[{CircleBox[{0.704561281337047,0.713883472609099},{0.3012418755803157,0.286116527390901},NCache[{Rational[-1,2] Pi,Pi},{-1.5707963267948966`,3.141592653589793}]],LineBox[{{-0.5082985143918236,0.4277669452181976},{0.7045612813370474,0.4277669452181969}}]}],{{{{0.5664850050486879,0.},{0.,0.6773257967103861}},{-0.2201331594382468,0.23035178076576013`}}}],GraphicsGroupBox[GeometricTransformationBox[{GeometricTransformationBox[CircleBox[{1.1281186011035418,0.8110388887561297},{0.3012418755803157,0.28611652739090143},NCache[{Rational[-1,2] Pi,Pi},{-1.5707963267948966`,3.141592653589793}]],{{{{-0.0436923783775125,-1.1945223020110638`},{0.8355565855835099,-0.04369237837751237}},{0.8084802717483834,-0.8768574570512992}}}],LineBox[{{-0.21002231725826281`,-0.22404391255958478`},{1.0028374784706082`,-0.22404391255958545`}}]},{{{{-0.5664830242176244,0.0017911903649896652`},{-0.001498071515779273,-0.6773234283017499}},{0.06019319850849453,0.18314776099507302`}}}]]}],{{-0.2112929433611883,-0.41264623955431734`}}]}];

(*-------------------------------------------------------------Saida-------------------------------------------------------------*)

girando=False;
giro=Dynamic[(t=If[girando,Clock[{0.,2000.Pi,0.005Pi},15000],0.];
Graphics[{Cyan,Rectangle[{25,25},{375,375}]
,Inset[grafico,{200,200},{-0.1426,0.2078},300,{Cos@(Setting@omega/7.59*t),Sin@(Setting@omega/7.59*t)}]
},PlotRangePadding->0,PlotRangeClipping->True,ImageSize->{200,Automatic}])];
slidervel=Graphics[{corfundo,Rectangle[{0,-0.5},{10,2}],Black,Dynamic@Text["v = "<>ToString[vv]<>" m/s",{5,1.5}],Text[ToString@vmin<>" m/s",{0.01,0},{-1,1}],Text[ToString@vmax<>" m/s",{9.99,0},{1,1}],Inset[Slider[Dynamic[vv],{vmin,vmax,0.1}(*,ImageSize->0.4{360,20}*)],{5,0.5},{0,0},{Automatic,Automatic}]},PlotRangePadding->0,PlotRangeClipping->True,ImageSize->{200,Automatic}];

(*-----------------Dados Nominais-----------------*)
linkdadosdeplaca=Graphics[{Pink, Rectangle[{0,0},{50,10}, RoundingRadius->2],Black,FontSize->14,Text["Dados nominais",{25,5}]}];
dadosdeplaca=Column[{"Nome: Turbina Vestas V90","Potência nominal: 2 MW","(Subscript[V, cut - in])=3m/s","(Subscript[V, nominal])=13m/s","(Subscript[V, cut - out])=25m/s","Gearbox= 1:112,8","----Gerador----","Tensão=660V","Frequência=50Hz","Rotação Nominal=1680rpm"}];

escolhatela=Grid[{{RadioButton[Dynamic[escolha],1],"Tela com Slider"},
{RadioButton[Dynamic[escolha],2],"Tela com Botões"}}];
maismenosvel=Dynamic@display["vv",passo->0.5,prefixo->"v= ",sufixo->" m/s",largura->13,estilofonte->{Red,Bold,FontSize->11},margem->0.25,min->0,max->30,ImageSize->{200,51}];
saida=Dynamic@Framed[Pane[
Switch[esc,
1,Column[{
Row[{Column[{
Grid[{{Null,Null,Null},{Null,Checkbox[Dynamic@girando],Style[" Giro",{FontFamily->"Arial"}]}}],
Framed[EventHandler[Dynamic@Pane[Row[{Show[figflash,ImageSize->{50,Automatic}],Show[figwind,ImageSize->{50,Automatic}]}],{120,120},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=1)}],FrameMargins->0,FrameStyle->{Opacity[0],Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig2,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=3)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig3,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=4)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig7,120{1,0.62},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=6)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@fig5,ImageSize->120],120{1,0.5},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=5)}],"LinkHand"]
}],
Framed[Pane[Dynamic@Show[Setting@giro,ImageSize->{440,440}],440,Alignment->{Center,Center}],FrameMargins->0,FrameStyle->{Thickness[0.1]}],Pane[Column[{fig1,EventHandler[linkdadosdeplaca,{{"MouseClicked",1}:>(MessageDialog[dadosdeplaca,WindowTitle->"Dados nominais",WindowFloating->True])}]}],{150,Automatic},Alignment->{Center,Center}]},Pane["",1]],
Row[{Dynamic@Show[slidervel,ImageSize->{250,50}],Panel[infotelamec,ImageSize->{400,80}]}]},Pane["",20],Alignment->Center]
,3,Column[{
Row[{Column[{
Grid[{{Null,Null,Null},{Null,Checkbox[Dynamic@girando],Style[" Giro",{FontFamily->"Arial"}]}}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@giro,ImageSize->{120,120}],{120,120},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=1)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Row[{Show[figflash,ImageSize->{50,Automatic}],Show[figwind,ImageSize->{50,Automatic}]}],120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=3)}],"Arrow"],FrameMargins->0,FrameStyle->{Opacity[0],Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig3,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=4)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig7,120{1,0.62},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=6)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@fig5,ImageSize->120],120{1,0.5},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=5)}],"LinkHand"]
}],
Framed[Pane[Column[{Style["Curva Potência Mecânica",{FontFamily->"Arial",FontWeight->Bold,FontSize->16}],Dynamic@Show[Setting@fig2,ImageSize->{440,Automatic}]},Alignment->Center],{440,440},Alignment->Center],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Pane[Column[{fig1,EventHandler[linkdadosdeplaca,{{"MouseClicked",1}:>(MessageDialog[dadosdeplaca,WindowTitle->"Dados nominais",WindowFloating->True])}]}],{150,Automatic},Alignment->{Center,Center}]},Pane["",1]],
Row[{Dynamic@Show[slidervel,ImageSize->{250,50}],Panel[infotelamec,ImageSize->{400,80}]}]},Pane["",20],Alignment->Center]
,4,Column[{
Row[{Column[{
Grid[{{Null,Null,Null},{Null,Checkbox[Dynamic@girando],Style[" Giro",{FontFamily->"Arial"}]}}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@giro,ImageSize->{120,120}],{120,120},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=1)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig2,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=3)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Pane[Row[{Show[figflash,ImageSize->{50,Automatic}],Show[figwind,ImageSize->{50,Automatic}]}],120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=4)}],"Arrow"],FrameMargins->0,FrameStyle->{Opacity[0],Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig7,120{1,0.62},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=6)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@fig5,ImageSize->120],120{1,0.5},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=5)}],"LinkHand"]
}],
Framed[Pane[Column[{Style["Curva Coeficiente de Potência",{FontFamily->"Arial",FontWeight->Bold,FontSize->16}],Dynamic@Show[Setting@fig3,ImageSize->{440,Automatic}]},Alignment->Center],{440,440},Alignment->{Center,Center}],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Pane[Column[{fig1,EventHandler[linkdadosdeplaca,{{"MouseClicked",1}:>(MessageDialog[dadosdeplaca,WindowTitle->"Dados nominais",WindowFloating->True])}]}],{150,Automatic},Alignment->{Center,Center}]},Pane["",1]],
Row[{Dynamic@Show[slidervel,ImageSize->{250,50}],Panel[infotelamec,ImageSize->{400,80}]}]},Pane["",20],Alignment->Center]
,5,
Column[{
Row[{Column[{
Grid[{{Null,Null,Null},{Null,Checkbox[Dynamic@girando],Style[" Giro",{FontFamily->"Arial"}]}}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@giro,ImageSize->{120,120}],{120,120},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=1)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig2,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=3)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig3,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=4)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig7,120{1,0.62},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=6)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Row[{Show[figflash,ImageSize->{50,Automatic}],Show[figwind,ImageSize->{50,Automatic}]}],120{1,0.5},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=5)}],"Arrow"],FrameMargins->0,FrameStyle->{Opacity[0],Thickness[0.1]}]
}],
Framed[Pane[Dynamic@Show[Setting@fig5,ImageSize->440],{440,440},Alignment->{Center,Center}],FrameMargins->0,FrameStyle->{Opacity[0],Thickness[0.1]}],Pane[Column[{fig1,EventHandler[linkdadosdeplaca,{{"MouseClicked",1}:>(MessageDialog[dadosdeplaca,WindowTitle->"Dados nominais",WindowFloating->True])}]}],{150,Automatic},Alignment->{Center,Center}]},Pane["",1]],
Row[{Dynamic@Show[slidervel,ImageSize->{250,50}],Panel[infotelamec,ImageSize->{400,80}]}]},Pane["",20],Alignment->Center]
,6,
Column[{
Row[{Column[{
Grid[{{Null,Null,Null},{Null,Checkbox[Dynamic@girando],Style[" Giro",{FontFamily->"Arial"}]}}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@giro,ImageSize->{120,120}],{120,120},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=1)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig2,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=3)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Dynamic@Pane[Setting@fig3,120{1,0.67},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=4)}],"LinkHand"],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Framed[MouseAppearance[EventHandler[Pane[Row[{Show[figflash,ImageSize->{50,Automatic}],Show[figwind,ImageSize->{50,Automatic}]}],120{1,0.62},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=6)}],"Arrow"],FrameMargins->0,FrameStyle->{Opacity[0],Thickness[0.1]}],
MouseAppearance[EventHandler[Dynamic@Pane[Show[Setting@fig5,ImageSize->120],120{1,0.5},Alignment->{Center,Center}],{{"MouseClicked",1}:>(esc=5)}],"LinkHand"]
}],
Framed[Pane[Column[{Style["Curva Torque",{FontFamily->"Arial",FontWeight->Bold,FontSize->16}],Dynamic@Show[Setting@fig7,ImageSize->{440,Automatic}]},Alignment->Center],{440,440},Alignment->{Center,Center}],FrameMargins->0,FrameStyle->{Thickness[0.1]}],
Pane[Column[{fig1,EventHandler[linkdadosdeplaca,{{"MouseClicked",1}:>(MessageDialog[dadosdeplaca,WindowTitle->"Dados nominais",WindowFloating->True])}]}],{150,Automatic},Alignment->{Center,Center}]},Pane["",1]],
Row[{Dynamic@Show[slidervel,ImageSize->{250,50}],Panel[infotelamec,ImageSize->{400,80}]}]},Pane["",20],Alignment->Center]
,_,"erro na variável esc"]
,{Automatic,Automatic}],FrameStyle->{Thickness[0.5]},Background->corfundo])],1500,Alignment->Center]

Curve-based selection of eletric motors (nb file ok, cdf file to be created)

Operation phases in an electric motor:

Acceleration: (Subscript[T, motor]) > (Subscript[T, res])

Braking: (Subscript[T, motor]) < (Subscript[T, res])

Constant speed: (Subscript[T, motor]) = (Subscript[T, res])

Eletrical-mechanical conversion can be modeled by a equivalent resistor, which is function of the slip (s), relative difference of the rotational speed of magnetic field and the rotational speed of rotor.

Eletric motor selection, by Vinicius Toquetti, with prof Milana Santos and prof Silvio Giuseppe Di Santo

Next planned steps

CDF deployment of notebooks about wind power and selection of motors

Deployment in web

Contribution to Wolfram Demonstration Project

Programmable Logic Controller (PLC) emulation with hardware integration

Thank you!

milanals@usp.br